Where did I mess up?
Mar 10, 2018 at 1:26am UTC
I'm working on a program that needs to calculate and display pay raises for 3 years. the pay raises needed are 3% 4% 5% and 6%. When I finished, my program doesn't work. I can enter an amount (other than -1) and it doesn't display anything.
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
#include<iostream>
using namespace std;
int main()
{
//Declare variables
double salary = 0.0;
double rate = 0.0;
while (1)
{
//Read salary
cout<<"Enter salary (-1 to stop) : " ;
while (cin >> salary && salary != -1)
cin>>salary;
//If sentinal is entered break loop
if (salary==-1)
{
cout<<"Bye!" <<endl;
break ;
}
else
{
cout<<"\nAnual Raises for next three years : " <<endl;
//Intializing rate to 0.03 i.e 3% of salary
rate = 0.03;
while (rate<0.07)
{
//display annual raise in amount
cout<<rate*100<<" % raise : " <<salary*rate<<endl;
//increment salary by raise amount
salary = salary + (salary*rate);
//Increment rate by 1%
rate = rate + 0.01;
}
}
cout << "Enter salary (-1 to stop) : " << endl;
}
return 0;
}
Mar 10, 2018 at 1:57am UTC
It's not perfect, but it's a start
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
#include<iostream>
using namespace std;
int main()
{
//Declare variables
double salary = 1.0;
double rate = 0.03;
//Read salary
cout<<"Enter salary (-1 to stop) : " ;
while (1)
{
cin >> salary;
cout << salary << endl; // Test
//If sentinal is entered break loop
if (salary==-1)
{
cout<<"Bye!" <<endl;
break ;
}
else
{
cout<<"\n Anual Raises for next three years : " << endl;
//Intializing rate to 0.03 i.e 3% of salary
while (rate < 0.07)
{
//display annual raise in amount
cout << rate*100 <<" % raise : " << salary*rate << endl;
//increment salary by raise amount
salary = salary + (salary*rate);
//Increment rate by 1%
rate = rate + 0.01;
}
}
cout << "Enter salary (-1 to stop) : " << endl;
}
return 0;
}
Topic archived. No new replies allowed.