#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
double minutes
(minutes >= 1.00)
int choice, A, B, C;
A = 1;
B = 2;
C = 3;
constdouble costA = 19.95, costB = 32.95, costC = 45.95;
double costTotal;
cout << "Which Package have you purchased?" << endl;
cout << "Package: A, B, or C?" << endl;
cin >> choice;
cout << setprecision(2) << fixed;
if (choice = A)
{
cout << "How many minutes spent on the phone during this month?" << endl;
double minutes;
cin >> minutes;
costTotal = costA + (minutes - 200) * 0.08;
cout << "Your monthly bill is: " << "$" << costTotal << endl;
}
elseif (choice = B)
{
cout << "How many minutes spent on the phone during this month?" << endl;
double minutes;
cin >> minutes;
costTotal = costB + (minutes - 600) * 0.05;
cout << "Your monthly bill is: " << "$" << costTotal << endl;
}
elseif (choice = C)
{
costTotal = costC;
cout << "Your monthly bill is: " << "$" << costTotal << endl;
}
return 0;
}
i also need to add a single loop in case someone makes an incorrect input but i'm not worried about it at the moment. My main concern is that i'm getting
if i remove the make the minutes = 1 then it works but i need the program to understand minutes needs to be greater than or equal to 1, and it still won't allow input for any of the if statements
1 2 3 4 5 6 7
Which Package have you purchased?
Package: A, B, or C?
A
How many minutes spent on the phone during this month?
Your monthly bill is: $-7404770507945427000000000000000000000000000000000000000
00000.00
Press any key to continue . . .
1. Unless he means you are limited to not using a break outside a switch control. Even then that sort of limitation is dubious.
2. If you are repeating lines like 25 to 27 then the code can be improved, simplified and debugged more easily.
3. Read the comments I made carefully. Your line 9 is doing nothing and I have already described how you solve the if minutes problem. Take it or leave it I guess. We are talking about nested if's - nothing special.
4. Initializing is not mandatory but it is a warning a good compiler will give you which is well worth taking head of and really at no cost.
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
double minutes;
char ch;
ch = 'A';
ch = 'B';
ch = 'C';
int choice;
choice = 'A', 'B', 'C';
constdouble costA = 19.95, costB = 32.95, costC = 45.95;
double costTotal;
cout << "Which Package have you purchased?" << endl;
cout << "Package: A, B, or C?" << endl;
cin >> choice;
cout << setprecision(2) << fixed;
if (choice == 'A')
{
cout << "How many minutes spent on the phone during this month?" << endl;
cin >> minutes;
costTotal = costA + (minutes - 200) * 0.08;
cout << "Your monthly bill is: " << "$" << costTotal << endl;
}
elseif (choice == 'B')
{
cout << "How many minutes spent on the phone during this month?" << endl;
cin >> minutes;
costTotal = costB + (minutes - 600) * 0.05;
cout << "Your monthly bill is: " << "$" << costTotal << endl;
}
elseif (choice == 'C')
{
costTotal = costC;
cout << "Your monthly bill is: " << "$" << costTotal << endl;
}
return 0;
}
still getting this:
1 2 3 4 5 6 7
Which Package have you purchased?
Package: A, B, or C?
A
How many minutes spent on the phone during this month?
Your monthly bill is: $-740477050794542700000000000000000000000000000000000000
00000.00
Press any key to continue . . .
it seems there is is an also overflow and i'm not sure what's causing it?
1. The loop must wrap around all of the stuff you have so far.
2. ... and the 'door' to the loop will only open while ( choice == 'A' or choice == 'B' or choice == 'C' or choice != 'Q' )
3. You might have to bracket choices eg ( choice == 'A) or (choice == ...) etc. It is better if you do anyway for clarity in you while statement.