Why does my windows shut down?

Both of my programs cause the window to restart when I select compile and I do not know why.

Problem:

should include a while loop that allows the user to continue entering employees as long as they want to continue.


[code]

int main()
{
Real payrate,hours, gross;

int again = 1;

while (again == 1);
{

cout << "Enter the employees hourly pay rate. \n";
cin >> payrate;

cout<< "Enter the total hours worked by employee. \n";
cin >> hours;

while (payrate > 18.25 || payrate < 7.50)
{
cout << "The valid value for pay rate is in the range. \n";
cout << " of $7.50 through $ 18.25. \n";
cout << "Enter a valid value for pay rate. \n";
cin >> payrate;
}

while (hours > 40 || hours < 0)
{
cout << "Please enter hours worked between 0 and 40. \n ";
cin >> hours;
}


gross = payrate * hours;
cout << "The gross pay of the employee is $ " << gross << endl;

cout << "Do you want to continue for another employee? Enter 1 for yes \n";
cout << "or 0 for no." << endl;
cin >> again;
}

}



Problem:

include a loop that displays income generated from ticket sales for each night. Shows are performed on Thursday, Friday and Saturday nights.


code:

int main()
{
int A, B, C ;
int TotalIncome[3];
for (int i=0; i<3; i++);
{


cout << "Enter number of seats sold in Section A: \n";
cin >> A;

cout << "Enter number of seats sold in Section B: \n";
cin >> B;

cout << "Enter a number of seats sold in Section C: \n";
cin >> C;

while (A < 0 or A > 300)
{
cout << "ERROR: Seats sold in Section A cannot be \n";
cout << "greater than 300 or negative.\n ";

cout << "Enter valid value for seats sold in section A: \n";
cout << "A value in the range of 0 to 300 inclusive. \n";
cin >> A;
}
while (B < 0 or B > 500)
{
cout << "ERROR: Seats sold in Section B cannot be \n";
cout << "greater than 500 or negative.\n ";

cout << "Enter valid value for seats sold in section C: \n";
cout << "A value in the range of 0 to 500 inclusive. \n";
cin >> B;
}
while (C < 0 or C > 200)
{
cout << "ERROR: Seats sold in Section C cannot be \n";
cout << "greater than 200 or negative.\n ";

cout << "Enter valid value for seats sold in section C: \n";
cout << "A value in the range of 0 to 200 inclusive. \n";
cin >> C;
}
TotalIncome[i] = (A * 20) + (B * 15) + (C * 10);
}
for (int i=0; i<3; i++)
{

cout << "The total income generated from ticket sales \n ";
cout << "of all sections is $ " << TotalIncome;
}

}
while (payrate > 18.25 || payrate < 7.50) is wrong:
- || is OR and here it should be AND &&
- (payrate > 7.50) && (payrate < 18.25)
- payrate variable is not initialized, thus it might not always execute code in while in 1st run
Topic archived. No new replies allowed.