Sign in with
Sign up | Sign in
Your question
Solved

C++ program help

Tags:
Last response: in Applications
Share
February 23, 2014 4:52:56 PM

Can anyone tell me why this wont continue past the first cin statement?


#include <iostream>
#include <cctype>
#include <string>
#include <iomanip>
#include <cmath>
//ADD OTHER INCLUDE FILES HERE

using namespace std;

int main()
{
//VARIABLE DEFINITIONS
char choice, A, B, C;
double tax = .0975, price, taxAmount, total, totalSize;
int spongeCake, quantity, size, buttercream, fondant;

const int increment = 2;


string line(80, '-');

do
{
cout << "\t\t\tCAKE BOSS\n" << endl;
cout << "What would you like to do, Buddy?\n" << endl;

cout << "A - SELL A CAKE\n";
cout << "B - MAKE A CAKE\n";
cout << "C - END PROGRAM\n";
cout << "CHOOSE A, B, or C: " << endl;
cin >> choice;

while (choice == C || choice == B || choice == A)
{
cout << "Invalid. Please enter A valid selection, either A, B, or C.\n";
cout << "Press enter to continue and try again.\n";
cin >> choice;
}

switch (choice)
{
//SELL A CAKE
case 1:
choice == A;
cout << line << endl;
cout << setw(44) << "SELL CAKE" << endl << endl;
cout << "How many cakes have you sold?\n" << endl;
cin >> quantity;
cout << "What is the price of one cake?\n" << endl;
cin >> price;
total = quantity * price;
taxAmount = total * tax;

cout << setprecision (3) << fixed << endl;
cout << setw(15) << "TOTAL" << "\t$" << setw(10) << total << endl;
cout << setw(15) << "TAX AMOUNT" << "\t$" << setw(10) << taxAmount << endl;
cout << setw(15) << "TAX" << "\t$" << setw(10) << tax << endl;
break;
// Make A Cake
case 2:
choice == B;
cout << line << endl;
cout << setw(44) << "MAKE CAKE";
cout << "How large is the largest cake in inches?\n";
cout << "Must be an even number larger than 8.";
cin >> size;
while ( size % 2 == 0 )
{
cout << "Please enter an even number greater than 8\n";
cin >> size;
}
fondant = (size + 8) * 2;
buttercream = size / 8;
cout << line << endl;
cout << setprecision(2) << fixed << endl;
for (size = 1; size <= 100; size += 2)
{
cout << size << endl;
cout << "PRESS ENTER TO CONTINUE" << endl;
}
break;

default :
cout << "INVALID INPUT. Please enter A, B, or C." << endl;
}

} while (choice != C);

return 0;
}

More about : program

Best solution

February 23, 2014 5:24:55 PM

while (choice == C || choice == B || choice == A) I don't think this is correct. but its been awhile

I think its thinking A,B,C are declared variables to store info

"char choice, A, B, C;"

and as such you never assigned values to A, B, and C even though you set them as a storage value. you would need to store A to A, B to B and C to C

so it needs to be

char choice, A=A, B=B, C=C;

I think. that way char A has "A" stored to it.

understanding what im saying? its all because you confused yourself by using single letters as a storage holder.
the other option would be to change

while (choice == C || choice == B || choice == A) to while (choice == "C" || choice == "B" || choice == "A")
and remover your declared characters A,B,C alltogether

Share
February 23, 2014 7:40:52 PM

I'll try it all out and see if it works thank you for your advice.
m
0
l
!