HELP!

SO... trying to finish this program before its due tonight and i am stuck i cant get the program to work. ANY HELP IS GREATLY APPRECIATED!

The description is:In this assignment, you will be writing a C++ program for ATM machines to serve multiple customers. Each customer has a Personal Identification Number (PIN), and there are two types of customers. Type 1 customers have an odd PIN number and type 2 customers have an even PIN number. A type 2 customer will be charged $1 if the amount requested is not a multiple of 5.

This is what i have so far.....

#include <iostream>

using namespace std;



const float MIN_PIN = 1000;
const float MAX_PIN = 9999;
const float MIN_AMOUNT = 100;
const float MAX_AMOUNT = 1000;
const int TWENTY = 20;
const int TEN = 10;
const int FIVE = 5;
const int ONE = 1;


int number_twenty(int);
int number_ten(int);
int number_five(int);
int number_one(int);


int main()
{

int amount;
int pin;
char answer;

cout << "Enter your PIN please: "; //Prompts the user to enter a PIN
cin >> pin;
cout << endl;

if (pin != -1) //The program will terminate if -1 is entered as PIN
{
while (pin <= MIN_PIN || pin >= MAX_PIN) //Check to see if a valid PIN is entered
{
cout << "Invalid PIN: " << pin <<"."<< endl <<endl;
cout << "Enter your PIN please: ";
cin >> pin;
cout << endl;
}
if (pin % 2 == 0) //Determines if the pin is a type 2
{
cout << "Enter the amount to be withdrawn: " << endl; //Asks the user for the pin
cin >> amount; //User enters the pin

while (amount < MIN_AMOUNT || amount > MAX_AMOUNT) //Checks to make sure the amount is within the range
{
cout << "Invalid amount: " << amount << endl;
cout << "Enter the amount to be withdrawn: " << endl;
cin >> amount; //If invalid, the user is prompted to enter the pin again
}
if (amount % 5 != 0) //If the amount is not a multiple of 5 the user is told they
//will be charged $1
{
cout << "You are a type 2 customer, but the amount you ";
cout << "requested was: " << amount << endl;
cout << "You will be charged $1 for changing your setting. " << endl; //Tells the user they will be charged
cout << "Do you want to be charged $1? (Y/N) ";
cin >> answer;
if ( answer == 'y' || answer == 'Y') //Askes if they want to continue
{
cout << "You have been charged $1." << endl; //Tells the person how many bills they recieved
cout << "You are recieving the following bills:" << endl;
cout << " Number of $20 bills: " << number_twenty(amount) << endl;
cout << " Number of $10 bills: " << number_ten(amount) << endl;
cout << " Number of $5 bills: " << number_five(amount) << endl;
cout << " Number of $1 bills: " << number_one(amount) << endl;
cout << "Enter your PIN please: " << endl;
cin >> pin;
}

else
{
cout << "Enter the amount to be withdrawn: " << endl;
cin >> amount; //If they say no they are prompted to enter
}
}


}
else
cout << "Enter the amount to be withdrawn: " << endl; //Asks type 1 users how much they want to withdraw
cin >> amount;

while (amount < MIN_AMOUNT || amount > MAX_AMOUNT) //Checks to make sure the amount is within the range
{
cout << "Invalid amount: " << amount << endl;
cout << "Enter the amount to be withdrawn: " << endl;
cin >> amount; //If invalid, the user is prompted to enter the pin again
}

cout << "You requested: " << amount << endl;
cout << "You are recieving the following bills:" << endl; //Tells the person how many bills they recieved
cout << " Number of $20 bills: " << number_twenty(amount) << endl;
cout << " Number of $10 bills: " << number_ten(amount) << endl;
cout << " Number of $5 bills: " << number_five(amount) << endl;
cout << " Number of $1 bills; " << number_one(amount) << endl;
cout << "Enter your PIN please: " << endl;
cin >> pin;


}
else
{
cout << "You entered -1." << endl;
cout << "The program will terminate!" << endl;
}

return 0;
}


int number_twenty(int amount)
{

int number_20;
number_20 = amount / TWENTY;
return number_20;

}
int number_ten(int amount)
{
int number_10;
number_10 = ((amount - (number_twenty(amount) * TWENTY)) / TEN);
return number_10;
}
int number_five(int amount)
{
int number_5;
number_5 = ((amount - (number_twenty(amount) *TWENTY) - (number_ten(amount) * TEN)) / FIVE);
return number_5;

}
int number_one(int amount)
{
int number_1;
number_1 = ((amount - (number_twenty(amount) *TWENTY) - (number_ten(amount) * TEN) - (number_five(amount) * FIVE)) / ONE);
return number_1;
}
I fixed some of the errors in your code. It should work as long as you don't place any non integer characters in your input spaces.
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <iostream>

using namespace std;

// ** You're ammounts are int's. As seen in main() ** //
const int MIN_PIN = 1000;
const int MAX_PIN = 9999;
const int MIN_AMOUNT = 100;
const int MAX_AMOUNT = 1000;

const int TWENTY = 20;
const int TEN = 10;
const int FIVE = 5;
const int ONE = 1;

int number_twenty(int);
int number_ten(int);
int number_five(int);
int number_one(int);

int main()
{

    int amount;
    int pin;
    char answer;

    cout << "Enter your PIN please: "; //Prompts the user to enter a PIN
    cin >> pin;
    cout << endl;

// ** Isn't this a while? ** //
    while (pin != -1) //The program will terminate if -1 is entered as PIN
    {
        while (pin <= MIN_PIN || pin >= MAX_PIN) //Check to see if a valid PIN is entered
        {
            cout << "Invalid PIN: " << pin <<"."<< endl <<endl;
            cout << "Enter your PIN please: ";
            cin >> pin;
            cout << endl;
        }

		cout << "Enter the amount to be withdrawn: " << endl;
		cin >> amount; //User enters the ammount

		while (amount < MIN_AMOUNT || amount > MAX_AMOUNT) 
		//Checks to make sure the amount is within the range
		{
			cout << "Invalid amount: " << amount << "\nEnter the amount to be withdrawn: ";
			cin >> amount; //If invalid, the user is prompted to enter the pin again
		}
		


// ** Clutter reduce. 'not n%2` is the same as makieng a check if it returns 0. ** //
// ** If `ammount % 5` returns 0 then the if won't execute. Same as != 0. ** //
        if (not (pin % 2) && amount % 5) //If the amount is not a multiple of 5 the user is told they will be charged $1
        {
// ** Clutter reduce. You can chain cout's. ** //
// ** Two ways: Use Double quotes, and as long as you don't put any variables between them ** //
// ** They will be chained by Compiler. Need a newline? use '\n' ** //
// ** Otherwise just but << between strings and remember to use '\n'. This saves some thinking. ** //
			cout << "You are a type 2 customer, but the amount you"
				"\nrequested was: " << amount <<
				"\nYou will be charged $1 for changing your setting."
				"\nDo you want to be charged $1? (Y/N) ";
			cin >> answer;
			
			if (answer == 'y' || answer == 'Y') //Askes if they want to continue
				cout << "You have been charged $1.\n"; //Tells the person how many bills they recieved
			else
				while (amount % 5)
				{
					cout << "Enter the amount to be withdrawn: ";
					cin >> amount; //If they say no they are prompted to enter
					if (amount % 5)
						cout << "Not a multiple of 5.\n";
				}
		}

		cout << "You requested: " << amount <<
			"\nYou are recieving the following bills:"
			"\n Number of $20 bills: " << number_twenty(amount) <<
			"\n Number of $10 bills: " << number_ten(amount) <<
			"\n Number of $5 bills:  " << number_five(amount) <<
			"\n Number of $1 bills:  " << number_one(amount) <<
				
			"\n\nEnter your PIN please: ";
		cin >> pin;
	}
    if (pin == -1)
        cout << "You entered -1.\nThe program will terminate!" << endl;

    return 0;
}

// ** Changed to modulus. Less calls. ** //
int number_twenty(int amount)
{
	return amount / TWENTY;
}
int number_ten(int amount)
{
    return ((amount % TWENTY) / TEN);
}
int number_five(int amount)
{
	return ((amount % TEN) / FIVE);
}
int number_one(int amount)
{
	return ((amount % FIVE) / ONE);
}
Last edited on
Topic archived. No new replies allowed.