Easy fix?

closed account (LEUk4iN6)
I got it so when I enter a negative number for hours it asks for it again, but after I put that in, I want it to ask for payRate next. Any help?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace std;

// Allows you to just change the number in 1 spot.
const int SIZE=7;

int main()
{
	int empID[SIZE];
	int hours[SIZE];
	double payRate[SIZE];
	double wages[SIZE];

	for(int x=0; x<SIZE; x++)
	{
		cout << "Enter ID: ";
		cin >> empID[x];
		cout << "Enter hours: ";
		cin >> hours[x];
		if(hours[x] < 0)
			cout << "Please enter a integer value greater than 0!" << "\t" << "Enter hours: " << endl;
		else 
			cout << "Enter payRate: ";
		cin >> payRate[x];
		if(payRate[x] < 0)
			cout << "Please enter a positive pay rate." << endl;
		else
			wages[x] = hours[x] * payRate[x];
			cout << "The wages are " << wages[x] << endl;
	}
	return 0;
}
look at line 20. You ask the user to re-enter the hours, but you never actually get the hours from the user a second time. You go straight to the cin >> payRate[x] line.

You have a similar problem on line 60. You ask for the pay rate a second time, but never actually take it a second time.

You also put the "Enter payRate" line in an else statement.... but do you really want it to be conditional? From your question, it doesn't sound like it.


Not every 'if' needs an 'else'.
Topic archived. No new replies allowed.