would like to exit loop with Y/n

Hello, everything works but I am having trouble exiting the program and having the user repeat the steps. Please advise on what to do

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  n ()
{
	int  i,rate, overtime,number;
	double base;
	string name; 
	char user;
	//Formula 	
	base= rate*number;
	double salary = rate * number;
	
	
	for (i=0; i==i;++i)
	{	
	cout << " What is the first name of the employee?: " ;
	cin >> name ;
	
	
	
	cout <<"how many hours did " << name <<  " work ?";
	cin >> number;
	while ( number <0)
		{
	

    cout << "please enter a valid value for hours worked ";
    cin >> number;
	}
	
	cout << " please enter your rate of your employment?";
	cin>> rate; 
	 while ( rate<0)
	 { 
	  cout << " please enter a valid value for rate" ;
	  cin >>rate;
	 }
		//Formula 	
			base= 40*rate;
			salary = rate * number;
	if (number > 40)
       {
              overtime = (number - 40) * 1.5 * rate;
              
       }
    else if (number <= 40)
         {
              salary = rate * number;
         }
	
	
	cout
	<< "\n\t________________________________________________________"
	<< "\n\t|";  cout<< "\tTotal number of hours :"<<number <<"\t\t\t|"
	<< "\n\t|";  cout<< "\tPay rate " << rate <<"\t\t\t\t\t|"
	<< "\n\t|";	 cout<< "\tNumber of hours (overtime) "<< (number-40) <<	"\t\t\t|"
	<< "\n\t|";	 cout<< "\tBase salary :"<< base  <<"\t\t\t\t|"
	<< "\n\t|";  cout<<"\tOvertime pay : " << overtime <<"\t\t\t\t|"
	<< "\n\t|";	 cout<<"\tTotal pay : "<< (base+overtime)<<"\t\t\t\t|"
	<<"\n\t________________________________________________________"<<endl;
	
	
     do
	{
	
       cout<< "\nDo you want to add more employee(s) to calculate";
       cout<< "please enter Y for yes or N for no";
       cin >> user;
   	}
while((user =='Y')&&(user =='y')||(user!='N')&&(user !='n'));
       
		
	}
	
	
		
	
		
	
	
	
		
	

		system ("pause");
		return 0;
}
Last edited on
You did not post your full code. And your code does not compile.
Additionally, you are missing the function main().
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <string>

using namespace std;

int main ()
{
	int  i,rate, overtime,number;
	double base;
	string name; 
	char user;
	//Formula 	
	base= rate*number;
	double salary = rate * number;
	
	for (i=0; i==i;++i)
	{	
	cout << " What is the first name of the employee?: " ;
	cin >> name ;
		
	cout <<"how many hours did " << name <<  " work ?";
	cin >> number;
	while ( number <0)
		{
	

    cout << "please enter a valid value for hours worked ";
    cin >> number;
	}
	
	cout << " please enter your rate of your employment?";
	cin>> rate; 
	 while ( rate<0)
	 { 
	  cout << " please enter a valid value for rate" ;
	  cin >>rate;
	 }
		//Formula 	
			base= 40*rate;
			salary = rate * number;
	if (number > 40)
       {
              overtime = (number - 40) * 1.5 * rate;
              
       }
    else if (number <= 40)
         {
              salary = rate * number;
         }
	
	
	cout
	<< "\n\t________________________________________________________"
	<< "\n\t|";  cout<< "\tTotal number of hours :"<<number <<"\t\t\t|"
	<< "\n\t|";  cout<< "\tPay rate " << rate <<"\t\t\t\t\t|"
	<< "\n\t|";	 cout<< "\tNumber of hours (overtime) "<< (number-40) <<	"\t\t\t|"
	<< "\n\t|";	 cout<< "\tBase salary :"<< base  <<"\t\t\t\t|"
	<< "\n\t|";  cout<<"\tOvertime pay : " << overtime <<"\t\t\t\t|"
	<< "\n\t|";	 cout<<"\tTotal pay : "<< (base+overtime)<<"\t\t\t\t|"
	<<"\n\t________________________________________________________"<<endl;
	
       cout<< "\nDo you want to add more employee(s) to calculate";
       cout<< "please enter Y for yes or N for no ";
       cin >> user;

	   if(user == 'N' || user == 'n') break;
		
	}

		system ("pause");
		return 0;
}


http://cpp.sh/5cjtk
Last edited on
sorry, the main function ()- is there. I just didnt paste it from my complier. Also, i used a Do-while loop but the program is not exiting when i input the request
Thank you !, Tencacle . I thought I had to used a while loop to exit not an IF loop. Thank you. I just learned something
Tenacle wrote:
http://cpp.sh/5cjtk

How do you give links to cpp.sh like that with the code already loaded up when you click the link?

I would want to know since I want to give links to cpp.sh with the code already there.
Sorry,
the program works when the hours are over 40 but they do not work when its less than 40. do I need to write something else ?
Sorry,
the program works when the hours are over 40 but they do not work when its less than 40. do I need to write something else ?

Can you better describe your problem?
sure,
when I put 41, the programs runs correctly and the output is correct, however,
when running the program with 40 hours, it still calculates it with overtime pay. I would like the program to only calculate when the hours are greater than 40. I hope I explain correctly
Last edited on
Your final code, it is.
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <string>

using namespace std;

int main ()
{
	int  i,rate, overtime,number;
	double base;
	string name; 
	char user;
	//Formula 	
	base= rate*number;
	double salary = rate * number;
	
	for (i=0; i==i;++i)
	{	
	cout << " What is the first name of the employee?: " ;
	cin >> name ;
		
	cout <<"how many hours did " << name <<  " work ?";
	cin >> number;
	while ( number <0)
		{
	

    cout << "please enter a valid value for hours worked ";
    cin >> number;
	}
	
	cout << " please enter your rate of your employment?";
	cin >> rate; 
	 while ( rate<0)
	 { 
	  cout << " please enter a valid value for rate" ;
	  cin >>rate;
	 }
		//Formula 	
			base = 40 * rate;
			salary = rate * number;

	if (number > 40)
       {
              overtime = (number - 40) * 1.5 * rate;
       }
    else if (number <= 40)
         {
			  overtime = 0;
              salary = rate * number;
         }
	
	
	cout
	<< "\n\t________________________________________________________"
	<< "\n\t|";  cout<< "\tTotal number of hours :"<<number <<"\t\t\t|"
	<< "\n\t|";  cout<< "\tPay rate " << rate <<"\t\t\t\t\t|"
	<< "\n\t|";	 cout<< "\tNumber of hours (overtime) "<< (number - 40) <<	"\t\t\t|"
	<< "\n\t|";	 cout<< "\tBase salary :"<< salary  <<"\t\t\t\t|"
	<< "\n\t|";  cout<<"\tOvertime pay : " << overtime <<"\t\t\t\t|"
	<< "\n\t|";	 cout<<"\tTotal pay : "<< (salary+overtime)<<"\t\t\t\t|"
	<<"\n\t________________________________________________________"<<endl;
	
       cout<< "\nDo you want to add more employee(s) to calculate";
       cout<< "please enter Y for yes or N for no ";
       cin >> user;

	   if(user == 'N' || user == 'n') break;
		
	}

		system ("pause");
		return 0;
}


http://cpp.sh/8wd2
Last edited on
Topic archived. No new replies allowed.