1. Frothy Coffee!
Join Date
Jan 2006
Beans
239

## quick C++ question

I was curious to know why when I enter a number of hours more than 169 does my program just doesn't end and give the statement?

Code:
```#include <iostream>

float hours; // how many hours the employee worked for that week
float wages; // the employees hourly wage
float paycheck; //employees weekly pay
float overtime; //time and half
int impossible; // impossible number of hours to work in a week

int main()
{
impossible = 168;

std::cout << "Enter how many hours you worked: ";
std::cin >> hours;
std::cout << "Enter your hourly wage here: ";
std::cin >> wages;

if (hours > impossible)
{
std::cout << "It is impossible to work that long in seven days.\n";
paycheck == 0;
}
else if (hours < 40)
{
paycheck = hours * wages;
std::cout << "You have earned \$"<< paycheck << " for this week.\n";
}
else (hours > 40);
{
overtime = (hours - 40) / 2;
paycheck = (hours + overtime) * wages;
std::cout << "You have earned \$"<< paycheck << " for this week.\n";
}
return (0);
}```
Code:
```Enter how many hours you worked: 190
Enter your hourly wage here: 8
It is impossible to work that long in seven days.
You have earned \$2120 for this week.```

2. ## Re: quick C++ question

Code:
`else (hours > 40);`
This line is missing an "if" and has an extra ;

It should look like this:

Code:
`else if (hours > 40)`

3. Frothy Coffee!
Join Date
Jan 2006
Beans
239

It worked!

Thank You.

4. ## Re: quick C++ question

Remember that in C and C++ everything is a statement.

For instance, this program will actually compile:

Code:
```int main()
{
1;
{2;}
4 != 8;
16 + 32;
64 < 128;
return 0;
}```
You may get a warning telling you that the statements don't do anything, but it compiles none-the-less... And does absolutely nothing but return 0.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•