calculations cmath needed inclusion?

1
2
3
4
5
6
7
8
9
10
11
12
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;
}



i do not know how to display bills function means at beginning of this algorithm i need to find a new passion perhaps or im just to retarded for this stuff... :/
Calculation issue do i need to include cmath on this its a part of a program im working on errors beyond this point so ill give the parts that are messed up


heres the algorithm being used.

//
// 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

If possible show me in //s what i did wrong here this is how i understood it to be i just need to know what i did wrong im rereading this book now because i must have missed something majorly in the format /structure and proper syntax rules really over whelmed on this;/
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*int main()
{*/
int ones, fives, tens, twenties, temp,;//remove the final comma; it just needs a semi-colon
twenties = (dollars/20);/*change this to *twenties = ((dollars-(dollars%20))/20;* 
without the asterisks, since it would otherwise give a decimal (this way, when you input 
24, it will do (24-4)/20 versus 24/20)*/
temp = (dollars%20);/*make this instead *temp = dollars-(twenties*20);* without the \
asterisks, so that the temp value is equal to the remainder left over after you broke it 
into 20 dollar bills*/
tens = (temp/10);//same as with twenties, but replace dollars with temp like you did
temp = (temp%10);//same with the first temp
fives = (temp/5);//same as with tens
ones =(temp%5);//this is fine, actually, with the prior revisions
cout <<"The dollar amount of", dollars, " can be represented by the following monetary denominations" >> cin>>;/*replace the commas outside of the quotes with "<<"'s, add 
a colon after "denominations" inside of the quotes (grammatical nitpicking), and replace 
">>cin>>;" with "<< endl;" so that it makes a new line versus asking for another 
input*/
cout     << "     twenties:", twenties, tens:", tens, fives:",fives, ones:", ones " >> 
<<cin>>/* replace commas with "<<"'s, make sure that all words that are stated are fully encapsulated in quotation marks, and replace everything after the "s" in the 
"ones" outside of quotation marks with a semi-colon*/

return 0;
}


Also, be sure that there is an #including <iostream> and an using namespace std; above int main() {.
Last edited on
this is all one program its needed to this is part of the other the code flows down it doesn't apply the includes and stuff? why is this? just asking not questioning your work just curious is all
little confused ont the same aas twenties and replace with dollars so dollars should be temp there? and temp = should be like temp =(dollars? not understanding that to good elaborate a little im a little slow ;/
temp = dollars-(twenties*20); gives a error * needed at one of the 2 sides?
Let me quickly write up what it should look like in the end. I'll explain all of the syntax in comments.
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>

using namespace std;

int main()
{
    int dollar, bills;//only need two variables here
    while(true)//this way, it repeats itself until you type zero
    {
        cout << "Please type in the dollar amount, without cents, that you would like to convert to bills." << endl;
        cin >> dollar;//asks for the dollar amount
        if(dollar == 0)//if you typed 0
            break;//exit out of the loop, and thus the function
        bills = (dollar-(dollar%20))/20;//the number of 20-dollar bills is equal to the total number of bills minus the remainder of the total number of bills divided by twenty, all over twenty
        cout << endl << "The number of denominational bills for " << dollar << " dollars is:";//basic statement
        cout << bills;//state the number of twenties
        if (bills == 1)//if there's only 1 twenty
            cout << " twenty, ";//use singular
        else//otherwise
            cout << " twenties, ";//use plural
        dollar -= (bills*20);//set the dollar amount to the dollar amount minus all of the 20 dollar bills (-= works like this: A-=B is equal to A = (A-B))
        bills = (dollar-(dollar%10))/10;//the number of 10 dollar bills, calculated the same way as the number of 20-dollar bills
        cout << bills;//state the number of tens
        if (bills == 1)//if only 1 ten
            cout << " ten, ";//use singular
        else//otherwise
            cout << " tens, ";//use plural
        dollar -= (bills*10);//set the dollar amount to the dollar amount minus all of the 10 dollar bills
        bills = (dollar-(dollar%5))/5;//calculate the number of 5's
        cout << bills;//state the number of 5's
        if (bills == 1)//if only one five
            cout << " five, ";//use singular
        else//otherwise
            cout << " fives, ";//use plural
        dollar -= (bills*5);//set the dollar amount to the dollar amount minus all of the 5 dolalr bills
        cout << "and " << dollar;//state the number of one's (the leftover amount should be less than 5)
        if (dollar == 1)//if only a single one
            cout << " one.";//use singular
        else//otherwise
            cout << " ones.";//use plural
        cout << endl;//skip a line at the very end
    }//closes the while loop
    return 0;//confirm a successful run
}//closes main 


This should be using syntax that should be familiar to you, such as endl, cin, and cout. Otherwise, it is only significantly longer than yours because I am really nit-picky about grammar and such.
Last edited on
i see this helps alot to review here thanks a ton ispil i will dive in to this in the am getting a little tired thank you for your help have a great one thanks if its ok may i send you a message on questions i might have later? if not thats ok to i just want to nip this thing in the bud i need to understand this stuff and you knowing what ive been working with might help in being able to refer me to things i need help with. Again thank you!
Topic archived. No new replies allowed.