help what am i doing wrong here ;/

1
2
3
4
5
6
7
8
9
10
11
int dollars;
    cout << "Please enter the whole dollar amount (no cents!)." 
    cin>>;
}
         for (int input = 0; i < i++)}
    while(dollars<>0) { <<displayBills(dollars)
    
    {  cout << "Please enter the whole dollar amount (no cents!)." <<;
    <<cin>> dollars;
    for (int input = 0; i < i++)
    }


its supposed to be going by this code...

// 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
Um... quite a bit, actually. I mean, several semicolons missing, pointless for loops that aren't even done correctly, <<cin>> is completely meaningless... I recommend looking at the extensive documentation on this web site as to get a better understanding of the proper syntax of C++, as well as the ins and outs.
i know theres a lot wrong.. im having difficulty learning how to convert from pseudocode it seems really dont know what the code is expecting me to do based on my shit book im learning from this is all that makes sence to me from the examples im given there...
the <<cin>> i thought callls in the input or at least thats what my tutorial says on this book. for input functions so i guess i just take that out. i know just as much now as i did before posting happy day.
This is the answer, check it, study the basics again -C++ How to program book is a good choice-

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
#include <iostream>
using std::cout;
using std::cin;
using std::endl;


int main(){

int dollars;

cout<<"Please enter the a whole dollar amount (no cents!). Input 0 to terminate: ";
cin>>dollars;

while(dollars!=0){
        cout<<dollars;
        cout<<"\nPlease enter the a whole dollar amount (no cents!). Input 0 to terminate: ";
        cin>>dollars;
}//end while

//type your favorite pause statement HERE i.e "cin.ignore();" "system("pause");" 

//or whatever you want

return 0; //indicate successful termination
}//end main

Last edited on
Alright, let me go line-by-line to tell you how to fix all of the issues... or at the very least, what is the issue with each line.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int dollars;/*This should not have a semicolon, but rather a 
right-hand brace the line below*/
    cout << "Please enter the whole dollar amount (no cents!)."//Needs a semicolon 
    cin>>;//This requires a variable for the dollar amount to be placed into
}//This is an unnecessary brace
         for (int input = 0; i < i++)/*input should be i since you use i everywhere else in 
the loop, the statement "i < i++" should be two statements- "i < whatever value you 
desire" followed by a semicolon, and then i++. Two, this should be followed by a right-
hand brace*/
    while(dollars<>0) { <<displayBills(dollars)/*Well, the list of issues here:"<>" is not 
any form of comparison, displaybills is not defined anywhere, the "<<" prior to 
displaybills is unnecessary, the semcolon should be on a new line as well as the 
displaybills function, and there should be a left-hand brace at the very end of this*/
    
    {  cout << "Please enter the whole dollar amount (no cents!)." <<;/* This is a 
completely unnecessary statement. If you want the program to loop back to itself, 
enclose the entire thing in a while(true) statement, where if the dollar value is 0, you 
break out of the function. Two, the brace is unnecessary. Three, the "<<;" is also 
unnecessary- it should either be omitted, or be "<< endl;" instead*/
    <<cin>> dollars;// Remove the "<<" in front of this
    for (int input = 0; i < i++)/*Same comments as last for statement, as well as the fact 
that this for statement does nothing whatsoever*/
    }//What does this brace even close? 


There you go... Mind you, I am only providing constructive criticism. If you look at the documentation, you should be able to see several examples that should guide you in understanding C++ code.
Last edited on
thank you i prefer the constructive criticism on the for (int ... blah blah that i put i put a generic equation for what i thought it might look something like based on my book which im seeing is wrong as well Thanks for the // notes help me understand better what im doing wrong ive been watching vids on thenewboston.com and read most of the tutorial up to the point in the book im at and still rather lost perhaps its just that tough to learn or i have a comprehension problem on this stuff not sure. ill keep reviewing thanks for helping me on this.
also do you have instead of using namespace std; you list them? ive never seen that used is this madatory for this type of code or is that something different?
Last edited on
No, no. It's not mandatory. It's just good practice to, rather than "using namespace std" simply state the specific functions of which you are using from namespace std, or simply append "std::" in front of any function that you want to use inside the std namespace (cout, cin, string, et cetera. You'll know when you try to compile and it throws an error about it being a non-existent function that should exist in included files). At your level, it's not necessary- just throw in an "using namespace std" at the start. Only later will you need to use the other method, but for now it is fine. As to what eyenrique posted, I'm not quite sure that's the desired result- it lets you input a dollar amount- and then input another, and another, without actually doing anything. If you're doing what I think you're doing- trying to convert it to dollar bills (100's, 50's, 20's, 10's, 5's, and 1's) then you'll need a different function, which would likely use remainder division (% is the symbol for remainder division in C++, so 12 % 10 would return 2) to figure out the number of dollars left over after you break it into the highest, then second-highest, then third... then lowest denomination of dollar bill. If you need any help with setting up a function that does that, just ask here. Trust me- the documentation on this site goes a long way towards helping you understand C++.
i posted a new topic on the next part of this program ill copy it here so you can see it thanks ispil i think this might help figure out what im trying to do.. ;)
1
2
3
4
5
6
7
8
9
10
11
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;





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
Last edited on
i think your right tho its supposed to represent denominations or something the algorithm provided is from the book its confusing to be and im not sure how to do these functions this is completely new i think it needs a inclusion or something like cmath maybe i dunno as i said im clueless on this one.
I posted on your other topic. And no, it does not need cmath.
Oh right // displayBills(dollars)
i supposed just print 'display' the dollars amount
@zmlink you should post more exercise's details
good luck!
Topic archived. No new replies allowed.