I'm hoping I could get some help pointing me in the right direction. My lab assignment is asking us to write a simple program that asks the user for a price amount and you would always be paying more so there is always going to be change. My professor wants us to be able to write a loop that determines if there are "1" or "multiple" of each currency. For example if there is only 1 quarter he does not want the code to say "1 quarters" but instead "1 quarter". The other part I've been trying to work on is that I can only get my code to function when I output everything in "for" loops. I've been trying to get my code to not output currency that has "0" in it, so it skips over those and only outputs currency that is being used.
If anyone could point me in the right direction I would really appreciate it. Thanks!
So I've been thinking of a better way to accomplish the skipping over the unused currency but this is what I came up with by just using a bunch of "if statements". I was thinking maybe I could use a "switch"?
Unrelated to the code, not meaning to be a grammar nazi, but no apostrophe is needed for plurals.
Check the quantity in an if statement and if it is greater than one add the s to the end like so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
cout << "How many do you want?" << endl;
getline(cin, input);
int amount = input;
while(!int(input)){
cout << "A number please." << endl;
cin.sync();
cin.clear();
getline(cin,input);
}
if(int(input) > 1 && cointype(cointype.length()) != "y"){
output = output + "s";
} else {
// statement here or some crap.
}
if(cointype(cointype.length()) == "y"){
cointype(cointype.length()) = "ies"
}
cout << "That'll cost " << amount << " " << cointype << "!" << endl;
Thanks for the tip. I was working on another way of doing it (a more tedious way), basically by using a ton of if statements. It seems like it's working fine but I was wondering if these was a better way of doing this. I was thinking about using switch statements but couldn't figure out how to get it to work.