2013-08-27 31 views
-3

这是我必须为课程编写的代码。我想知道这是否对我之前的其他人有意义,然后再开始学习。我刚开始上课,我想了解我是否走上正轨。硬币计数的伪代码是否正确?

// Declares the Variables 
Main module 
    Declare Quarters As Float 
    Declare Dimes As Float 
    Declare Nickels As Float 
    Declare Pennies As Float 
    Declare Total_Amount As Float 
    // This is the name of the Program 
    Write “Coin Counter” 
    // This tells the user what the function of the program is 
    Write “This program will calculate the total value of a group of coins. Assume that the” Write “coins are the standard American coins: penny, nickel, dime, quarter.” 
    // This calls the sub modules to be executed 
    Call Input Data module 
    Call Perform Calculations module 
    Call Output Results module 
    // This lets us know that this is the end of the program 
    End Program 

Input Data module 
    // Get the number of American coins broken down by penny, nickel, dime, quarter. 
    Write “Enter the number of pennies you want to count.” 
    Input Pennies 
    Write “Enter the number of nickels you want to count.” 
    Input Nickels 
    Write “Enter the number of dimes you want to count.” 
    Input Dimes 
    Write “Enter the number of quarters you want to count.” 
    Input Quarters 

// Sets the value of the coins. 
Perform Calculations module 
    Set Pennies count 1 * 0.01 
    Set Nickels count 1 * 0.05 
    Set Dimes count 1 * 0.10 
    Set Quarters count 1 * 0.25 
    Set Total_Amount = Quarters + Dimes + Nickels + Pennies 

// Displays the value of the change the user entered 
Output Results module 
    Write “The total amount of Pennies is:” + Pennies 
    Write “The total amount of Nickels is:” + Nickels 
    Write “The total amount of Dimes is:” + Dimes 
    Write “The total amount of Quarters is:” + Quarters 
    // Displays the total of all the coins added together. 
    Write “The Total: $” + Total_Amount 
+2

结果这个问题似乎是题外话,因为它是关于一个代码审查。 –

+0

谢谢你让我知道。我添加了代码审查。 –

+0

1)增加了缩进,它似乎足够易读,除了这个 - “Set Pennies count 1 * 0.01”。我不知道那里发生了什么,尽管我知道它意味着什么。 2)这是关于[so]的主题。代码审查问题更多关于[codereview.se]的主题。更改标签不会改变这一点。 – Dukeling

回答

0
// Declare constant variables 
Constant Real PENVALUE = 0.01 
Constant Real NICKVALUE = 0.05 
Constant Real DIMVALUE = 0.10 
Constant Real QUARVALUE = 0.25 
Constant Real DOLLAR_AMOUNT = 1.00 

//Declare variables 
Declare Real pennies 
Declare Real nickels 
Declare Real dimes 
Declare Real quarters 
Declare Real totalAmount 

// Use inputs to get coin amounts 
Display “Enter the number of pennies:” 
Input pennies 

Display “Enter the number of nickels:” 
Input nickels 

Display “Enter the number of dimes:” 
Input dimes 

Display “Enter the number of quarters:” 
Input quarters 

// Multiple coin amounts by coin values and find sum 
Set totalAmount = (pennies * PENVALUE) + (nickels * NICKVALUE) + (dimes * DIMVALUE) +(quarters * QUARVALUE) 

// Compare totalAmount to DOLLAR_AMOUNT and give appropriate display 
If totalAmount = DOLLAR_AMOUNT Then 
Display “Congratulations you are the winner!!!” 
Else if totalAmount > DOLLAR_AMOUNT Then 
Display “You have more than a dollar.” 
Else totalAmount < DOLLAR_AMOUNT Then 
Display “You have less than a dollar.” 
End if 

我不得不做学校类似的事情,唯一的区别是在最后