I have to make a sample run look like this. I cannot seem to get this right.
what am i doing wrong. PLEASE HELP!
Sample run (as a suggestion)
Welcome to My Vending machine.
Select a coin to insert from below (1-4)
1. for dollar
2. for quarter
3 for dime
4 for nickel
Your choice (1-4): 7
Invalid choice. Please select again.
Your choice (1-4): 1
Inserted so far: $1.00 out of $4.05
Select a coin to insert from below (1-4)
1. for dollar
2. for quarter
3 for dime
4 for nickel
Your choice (1-4): 2
Now, back to your question.
if (num >= 0)
{
total_coins += num; //total up coins
cout << " Inserted so far: $ " << total_coins << " out of $" << TOTAL_COST << endl;}
"num" is a coin index, and "total_coins += num;" ??? Perhaps I may have to re-input it hundreds of times !!!
About "total_coins += num" ?....
You want (num > 0) (Dollar) and num <= 4 (NICKEL) ?
Then, why did you define those variables ? (They're redundant)
I can input : num = 224, 466 or 63578... (They're valid, ????)
It would be something like this :
1 2 3 4 5 6 7
if (num > 0 && num < 5){
if(num == 1)total_coins += DOLLAR;
if(num == 2)total_coins += QUARTER;
if(num == 3)total_coins += DIME;
if(num == 4)total_coins += NICKEL;
cout << " Inserted so far: $ " << total_coins << " out of $" << TOTAL_COST << endl;}
else cout << "Invalid choice. Please select again."; //display a message
There are a number of problems with your code, it doesn't work, it is poorly formatted, and worse than the OP's code. Your second post isn't any better.
The worse thing is that it could cause the OP to waste a lot of time trying to fix your errors.
@paetim
IMO, ignore Jackson.
Edit your post so it uses code tags - the <> button on the right, then we can give you advice from there. If you have compiler output, post that as well
@TheIdeasMan
I recommend you don't think too much. I, always never request anyone to try my own sources. All code & sources before any post are tested carefully. I tested the example and it's fine. NO ERRORS, NO CRASHES, NO WARNINGS !!!!!! I don't understand what you say, is there any awful point in the suggestion code? Then in your opinions, what is good, what is bad? What is missing, what is redundant? What is too high, what is wrong? And what is... !?!??!?!?!!?
You should note it's only a reference source, and there are many methods around. Hey TheBestIdeasMan, You should have a different idea better than me ???
@paetim
Don't be afraid. As TheIdeasMan said, maybe the code will never work perfectly 100%, but in some similar cases, maybe it'll able to help you.
Or follow the BestIdeasMan's advice, I'm totally sure many better knowledgeable people in the world in the world will help & answer you earnestly.... (I'm only just an opinion...)
Edit: This source is based on your demonstration program text. A small problem is int - float but I haven't made any change and ignored them because your source had defined them. If you want, simply divide the value by 100 (It should correct)
HTH