Codeblocks crashes when i enter the compile?

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;
}

}
Last edited on
Problem 1: If you want to allow the user to input as many times as they want, a while loop must fall over the entire process. An empty while loop at the end won't do anything. It would make the most sense to use a do-while loop.

Payrate and gross aren't initialized, so I assume they are elsewhere in the program that was not included....

Problem 2: An array of strings would probably not make sense in a project of this size. Whatever is most readable is generally the best, especially for a program like this.

Not sure exactly what you are asking about for the second problem. Different people have different opinions about what code should look like, and since I am a beginner as well, my opinion may not be the best. I have been told over and over that readability is key.
Topic archived. No new replies allowed.