Entering 6 values to see the output (Please help)

closed account (G2hvpfjN)
I have problem with my program when I build and run it, it makes me to enter the value 6 times to see the result. What I know is, when I declare more variables, I should enter more values to see the output, Even tho I am a beginner c++ coder, so a help might be useful for me <3. Code as shown.

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
int SalaryOfFrank1,SalaryOfSarah2,SalaryOfJohn3,Choice,Amount,Total; 
 
		cout<<"Please enter the employee ID number including the Basic Salary";
		cin >> Choice;
		cin >> SalaryOfFrank1;
		cin >> SalaryOfSarah2;
		cin >> SalaryOfJohn3;
		cin >> Amount;
		cin >> Total;
 
	if 	(Choice==1)
	{
 
		SalaryOfFrank1 = Amount;
		cout<<" \n Name: Frank \n\n Basic Salary: "<< SalaryOfFrank1 << endl;
		SalaryOfFrank1 = Amount * 5  /100;
		cout<<" \n Pension Contribution 5% of Basic Salary: "<< SalaryOfFrank1 << endl;
		Total = Amount + Amount * 5 /100;
		cout<<" \n The Total Salary Including the Basic Salary and Pension Contribution is: "<< Total << endl;
	
	}
	else if (Choice==2)  
	{
		SalaryOfSarah2 = Amount;
		cout<<" \n Name: Sarah \n\n Basic Salary: "<< SalaryOfSarah2 << endl;
		SalaryOfSarah2 = Amount * 5  /100;
		cout<<" \n Pension Contribution 5% of Basic Salary: "<< SalaryOfSarah2 << endl;
		Total = Amount + Amount * 5 /100;
		cout<<" \n The Total Salary Including the Basic Salary and Pension Contribution is: "<< Total << endl;
		

	}
	else if (Choice==3)
	{
		SalaryOfJohn3 = Amount;
		cout<<" \n Name: John \n\n Basic Salary: "<< SalaryOfJohn3 << endl;
		SalaryOfJohn3 = Amount * 5  /100;
		cout<<" \n Pension Contribution 5% of Basic Salary: "<< SalaryOfJohn3 << endl;
		Total = Amount + Amount * 5 /100;
		cout<<" \n The Total Salary Including the Basic Salary and Pension Contribution is: "<< Total << endl;
		
		
	}
	else 
	{
		cout<<"ERROR: unknown employee number is entered, please try again.";
	}
	
	return 0;
	
}
Last edited on
it makes me to enter the value 6 times

Well, you're doing 6 cin statements (lines 4-9). What do you expect?

What I suspect you want to do is ask only for choice at the top of the program. Then within the if statements for each employee, ask for the salary for the respective employee.

Also, why are you doing a cin of Total when you compute Total?

Be aware you doing integer arithmetic. You may not get the results you expect.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.



Last edited on
Registered users can post here. Sign in or register to post.