RERUNNING PROGRAM

I have been trying to figure this out for awhile now but I am not sure why my programs is not rerunning.




#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
#include <ctime>

using namespace std;

const double COLORADDED = 0.10;
const double REGFRAME = 0.15;
const double FANCYFRAME = 0.25;
const double CARDBOARD = 0.02;
const double GLASS = 0.07;
const double TAX = 0.0925;

int main()
{

string employeeName, customerName, color;
char frameType, colorChoice, x;
double width, height, subTotal, squareArea, glassPrice, total;
double cardBoard, colorPrice, tax, frame;

do
{

cout << "name: ";
getline(cin,employeeName);

if(employeeName.length() !=0)
{
cout << "Customor's name: ";
getline(cin,customerName);
}
else
{
cout << "*** Invalid name. *** Can't be empty.";
return 0;
}

if(customerName.length() !=0)
{
cout << "Frame Width [3-72]: ";
cin >> width;
}
else
{
cout << "*** Invalid Width ***";
return 0;
}

if (width >= 3 || width <= 72)
{
cout << "Frame Height [3-72]: ";
cin >> height;
}
else
{
cout << "*** Invalid Height ***";
return 0;
}

if (height >= 3 || height <= 72)
{
squareArea = (height * width);
glassPrice = (squareArea * GLASS);
cardBoard = (squareArea * CARDBOARD);
cout << "Frame Type [R/F]: ";
cin >> frameType;
}
else
{
cout << "*** Invalid Frame Type ***";
return 0;
}

//ask for frame type or so invalid input
switch (frameType)
{
case 'f':
case 'F': cout << "Special Frame Color? ";
cin >> colorChoice;
cout << endl;
switch (colorChoice)
{
case 'y':
case 'Y':cout << " > ";
cin >> color;
cout << ">>>>> Processing...." << endl;
colorPrice = (COLORADDED*height + COLORADDED*width);
frame = (FANCYFRAME*height + FANCYFRAME*width);
subTotal = (glassPrice + cardBoard + frame + colorPrice);
break;
case 'n':
case 'N': frame = (FANCYFRAME*height + FANCYFRAME*width);
subTotal = (glassPrice + cardBoard + frame);
color = "white";
break;
default : cout << "*** Not Valid **";
return 0;
}
break;
case 'r':
case 'R': cout << "Special Frame Color? ";
cin >> colorChoice;
cout << endl;
switch (colorChoice)
{
case 'y':
case 'Y':cout << " > ";
cin >> color;
cout <<">>>>> Processing...." << endl;
frame = ((REGFRAME * height) + (REGFRAME * width));
colorPrice = ((COLORADDED * height) + (COLORADDED * width));
subTotal = (glassPrice + cardBoard + frame + colorPrice);
break;

case 'n':
case 'N':frame = ((REGFRAME * height) + (REGFRAME * width));
subTotal = (glassPrice + cardBoard + frame);
color = "white";
break;

default : cout << "*** Not Valid ***";
return 0;
}
break;
}
// calculate total
cout << endl;
tax = subTotal * TAX;
total = subTotal + tax;

//time code
struct tm* timeinfo;
time_t rawtime;
time(&rawtime);
timeinfo = localtime(&rawtime);

cout << fixed << setprecision(2) << showpoint;
cout << setw(50) << setfill(' ') << "" << endl;
cout << setfill(' ');
cout << "NATHAN BROTHERS" << setw(35) << right << setfill(' ') << "Purchase Order" << endl<<endl;

cout << "714-756-1234" << endl<<endl;


{
for (int i = 0; i < 50; i++)
cout << char(45);
cout<<endl<<endl;
}
cout << "Date/Time: "; cout << asctime(timeinfo); cout << endl;
cout << "Your order was taken by "<< employeeName<<endl<<endl;
cout << "Customer: "<< customerName<<endl<<endl;

{
for (int i = 0; i < 50; i++)
cout << char(61);
cout << endl<<endl;
}

cout << setfill('.');
cout << left << setw(42) << "Frame Height " << " " << setfill(' ') << right << setw(6) << height << endl << endl;
cout << setfill('.');
cout << left << setw(42) << "Frame Width " << " " << setfill(' ') << right << setw(6) << width << endl << endl;
cout << setfill('.');
cout << left << setw(42) << "Frame Type " << " " << setfill(' ') << right << setw(6) << frameType << endl << endl;
cout << setfill('.');
cout << left << setw(42) << "Color " << " " << setfill(' ') << right << setw(6) << color << endl << endl;

{
for (int i = 0; i < 50; i++)
cout << char(45);
cout<<endl<<endl;
}

cout << setfill(' ');
cout << left << setw(15) << "Frames" << right << setw(25) << "$" << right << setw(10) << frame << endl << endl;
cout << left << setw(15) <<"Cardboard Back" << right << setw(25) << "$" << right << setw(10) << cardBoard << endl << endl;
cout << left << setw(15) << "Glass" << right << setw(25) << "$" << right << setw(10) << glassPrice << endl << endl;

{
for (int i = 0; i < 50; i++)
cout << char(45);
cout<<endl<<endl;
}

cout << right << setw(34) << "SUBTOTAL" << right << setw(6) << "$" << right << setw(10) << subTotal << endl << endl;
cout << right << setw(34) << "TAX(9.25%)" << right << setw(6) << "$" << right << setw(10) << tax << endl << endl;
cout << right << setw(34) << "TOTAL" << right << setw(6) << "$" << right << setw(10) << total << endl << endl;
{
for (int i = 0; i < 50; i++)
cout << char(61);
cout<<endl<<endl;
}
cout<<"THANK YOU for your order"<<endl<<endl;


cout<< "Do you have more employees?";
cin>>x;
}

while(x == 'y' || x == 'Y');

return 0;
}
That code compiles and runs. If you can't get it to run, the problem is not in your code. Look to your IDE.
What is IDE? sorry.
It does run but when i press 'y' to rerun the program it says name: Invalid name cant be empty. It doesnt even give me the chance to type the name. It just goes straight to invalid name and I have to quit the program
When you press y to rerun, you are leaving some junk on the input line. That junk is then read in as the name. You must clear the junk from the input line.

1
2
3
4
5
6
7
8
9
#include <limits>
...
...
...

  cout<< "Do you have more employees?";
  cin>>x;
  cin.clear();cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
} while(x == 'y' || x == 'Y');
Last edited on
Well it works now but in the beginning I have to press enter in order for the name to come out. Is there any way I can make it come out on its own?
Read my post again. I moved it so you wouldn't have to.
Thanks so much. It is much appreciated =].
Topic archived. No new replies allowed.