Help me understand this pseudocode... bit confused on how i should be reading this...

Apr 19, 2013 at 2:44am
Start
// Declarations
// num dollars
// output "Please enter the a whole dollar amount (no cents!). Input 0 to terminate: "
// input dollars
// while ( dollars <> 0)
// displayBills(dollars)
// output "Please enter the a whole dollar amount (no cents!). Input 0 to terminate: "
// input dollars
// endwhile
// Stop
//
//
//
// displayBills(num dollars)
// Declarations
// num ones
// num fives
// num tens
// num twenties
// num temp
// twenties = dollars / 20
// temp = dollars % 20
// tens = temp / 10
// temp = temp % 10
// fives = temp / 5
// ones = temp % 5
// output "The dollar amount of ", dollars, " can be represented by the following monetary denominations"
// output " Twenties: ", twenties
// output " Tens: ", tens
// output " Fives: ", fives
// output " Ones: ", ones
// return



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
using namespace std;

int main()
{


    int dollars;
    cout << "Please enter the whole dollar amount (no cents!)." <<cin>>;

    while(dollars<>0) { <<displayBills(dollars)
        cout << "Please enter the whole dollar amount (no cents!)." <<;
    <<cin>> dollars;
    }
int ones, fives, tens, twenties, temp,;
twenties = (dollars/20);
temp = (dollars%20);
tens = (temp/10);
temp = (temp%10);
fives = (temp/5);
ones =(temp%5);
cout <<"The dollar amount of", dollars, " can be represented by the following monetary denominations" >> cin>>;
cout     << "     twenties:", twenties, tens:", tens, fives:",fives, ones:", ones " >> <<cin>>

return 0;

}

im not understanding what it is exactly the pseudocode wants me to do here.. is there 2 programs or just a header section before the int main? please help
Apr 19, 2013 at 3:01am
zmlink wrote:
im not understanding what it is exactly the pseudocode wants me to do here

not supprised that psudocode is awfull

Start = int main()
// Declarations
// num dollars
// output "Please enter the a whole dollar amount (no cents!). Input 0 to terminate: "
// input dollars
// while ( dollars <> 0) enter a while loop you need to decide which to use while(dollars > 0) or while (dollars < 0)
// displayBills(dollars) //this is a function call which means you need to make a function called displayBills
// output "Please enter the a whole dollar amount (no cents!). Input 0 to terminate: "
// input dollars
// endwhile
// Stop
//


----------------------------------------------------------------------------------------
//this should be in its own function
displayBills(num dollars) beginning of function
// Declarations
// num ones
// num fives
// num tens
// num twenties
// num temp

//these calculations are used to calculate differant dollars
// twenties = dollars / 20 calculates the amount of twenties in dollars
// temp = dollars % 20 calculates the remainder after the twenties are removed
// tens = temp / 10 ect
// temp = temp % 10 ect
// fives = temp / 5
// ones = temp % 5
/

//output the amount of each type of dollars
/ output "The dollar amount of ", dollars, " can be represented by the following monetary denominations"
// output " Twenties: ",
// output " Tens: ", tens
// output " Fives: ", fives
// output " Ones: ", ones
// return

output should look like
Twenties: 5
Tens: 5
Fives: 5
Ones: 5
Last edited on Apr 19, 2013 at 3:09am
Apr 19, 2013 at 3:08am
thanks i have no idea how to do the calculation parts ive never done anything like that before.. but at least i was right that it was messed up or more difficult then it needed to be.
Apr 19, 2013 at 3:27am
The calculations go like this.

Assume dollars equals 99

remember integer division gives you the number of times one number goes into another. for example 9 / 2 is 4 because 2 goes into 9 4 times evenly.

modulus division gives the remainder of integer division. so 9 % 2 is 1 because 1 is the remainder left over when you divide 9 / 2


twenties = dollars / 20 dollars is divided by 20 which gives you 4 this value is stored in twenties.

temp = dollars % 20 dollars still equals 99 at this point. modulus division is used to calculate the remainder of dollars divided by 20. 20 divides evenly into 99 4 times for a total of 80. 99- 80 is 19 the remainder is 19 and is stored in temp.

tens = temp / 10 temp equals 19 at this point. 19 is divided by 10 the result is 1 because 10 goes into 19 once. So tens equals 1

temp = temp % 10 uses modulus division to calculate the dollar amount after all tens have been removed from temp. temp equals 19. 10 divides evenly into 19 once leaving a remainder of 9. so temp equals 9.

fives = temp / 5 divides 9 by 5 to get the number of fives in nine. five divides evenly into 9 once so fives now equal one.

ones = temp % 5 temp still equals 9 here so we divide five into nine once to get a remainder of 4. So ones now equals 4


output
Twenties: 4
Tens: 1
Fives: 1
Ones: 4



Last edited on Apr 20, 2013 at 3:57am
Apr 20, 2013 at 1:37am
whoa.. thats insane lil difficult still cant get my function involving the calculations correct at all ;/ this might to be hard for my crap math skills lol
Topic archived. No new replies allowed.