Title: magic skip
Description: help pl0x
homeslice - January 25, 2007 06:00 PM (GMT)
Hey I'm having trouble finding how this program skips every single part after the user enters in a number for cents. It doesn't even go to the "would you like to run this program again" part, just skips.
| CODE |
#include <iostream>
using namespace std;
void input_change (int& num_cents);
void compute_coins(int number, int amount_left, int& quarters, int& dimes, int& nickels, int& pennies);
int main() { int cents, amount, quarter, dime, nickel, penny; char again; cout << "This program prompts the user for a value of change, and will " << "then output the equivilent value in quarters, dimes, nickels, " << "and pennies. The user may repeat the program."; do { input_change(cents); compute_coins(cents, amount, quarter, dime, nickel, penny); cout << "Would you like to run this program again? Enter \"Y\" " << "if yes \n"; }while (again == 'y' || again == 'Y'); return 0; }
void input_change(int& num_cents) { cout << "Please enter in an integer amount of change " << "less than 100 but greater than 0\n"; cin >> num_cents; while (num_cents <= 0 || num_cents >= 100) { cout << "cents cannot be " << num_cents << ", please " << "enter in another value for cents that is " << "less than 100 but greater than 0\n"; cin >> num_cents; } }
void compute_coins(int number, int amount_left, int& quarters, int& dimes, int& nickels, int& pennies) { quarters = number / 25; amount_left = number % 25; dimes = amount_left / 10; amount_left = amount_left % 10; nickels = amount_left / 5; amount_left = amount_left % 5; pennies = amount_left; cout << "You have " << quarters << " quarters and " << dimes << " dimes " << "and " << nickels << " nickels and " << pennies << "pennies\n"; }
|
thanks if you can help =P
biggoron - January 25, 2007 06:15 PM (GMT)
I may be foolishly missing something very obvious, but I don't see the part where you ask for yes/no input ._.
charlie - January 25, 2007 08:03 PM (GMT)
What input are you giving it? If you type in anything other than a number you will have problems, so "0.85" would be bad and ".85" would be bad and "85 cents" would be bad, but "85" would be good.
Then, it should output the stuff you tell it to output. Are you saying your output is not even appearing in the console window?
Of course, you are missing the part where you read in the answer for the yes/no question. Does your code work the first time and then fail the rest of the times after you type "y"?
homeslice - January 25, 2007 08:23 PM (GMT)
OMG sorry I'm stupid yeah I forgot to cin >> again -_-, nevermind it works now...Go ahead and delete this.
Zaqufant - January 25, 2007 09:20 PM (GMT)
Shonoby - January 25, 2007 09:41 PM (GMT)
Homeslice, look here is usually what i forget when i am programming:
- termination ;
- cout << || cin >>
- proper initialization
- proper passing
- proper reference
There are more but these are the most common.
Zaqufant - January 25, 2007 11:18 PM (GMT)
What do you mean "termination"?
Ravotus - January 26, 2007 12:02 AM (GMT)
He probably forgets his semicolons. :P
Shonoby - January 26, 2007 12:20 AM (GMT)
Yea, thats wat i mean termination key ';'