1

I want the program to display annual raise for years 1,2,3.

User enters year user enters annualSalary,

then if conditions are true the calculations are below.

But when I run it is not showing the calculation for any given year I input. Why? I went back over a few times and trying to determine what I am missing?

#include "stdafx.h"
#include <iomanip>
#include<iostream>
using namespace std;

int main()
{
    double annualSalary = 0; 
    int year = 0;
    double rate3 = 0.03; 
    double rate4 = 0.04; 
    double rate5 = 0.05; 
    double rate6 = 0.06;  
    double annualRaise = 0; 


    cout << fixed << setprecision(0); 

    cout << "enter current year (1 to 3) ";
    cin >> year;
    cout << "enter annual Salary";
    cin >> annualSalary; 


    if (year = 1)
        annualRaise = annualSalary * rate3;
    else if
        (year = 2)
        annualRaise = annualSalary * rate4;
    else if
        (year = 3)
        annualRaise = annualSalary * rate5; 

    return 0;
}
Shruder
  • 5
  • 9

2 Answers2

2

You need to add a print cout to see the result of your work :

if (year == 1)
{
    annualRaise = annualSalary * rate3;
    cout << "Salary : " << annualRaise << endl; // output the value
}


else if(year == 2)
{
    annualRaise = annualSalary * rate4;
    cout << "Salary : " << annualRaise << endl; // output the value
}



else if(year == 3)
{
    annualRaise = annualSalary * rate5;
    cout << "Salary : " << annualRaise << endl; // output the value
}


system("Pause"); //To be able to keep the console window open
Bo Halim
  • 1,716
  • 2
  • 17
  • 23
1

Use == to compare not = and add a cout to see the result.

if (year == 1)
        annualRaise = annualSalary * rate3;
    else if
        (year == 2)
        annualRaise = annualSalary * rate4;
    else if
        (year == 3)
        annualRaise = annualSalary * rate5;

cout << annualRaise;
Shadi
  • 1,701
  • 2
  • 14
  • 27
  • @ Shadi , thanks I modified per your notes. But it is still not appearing after I enter in the year and annual salary – Shruder Apr 01 '18 at 19:31
  • @Steven, I testes the code and it works with me. Have you added the `cout << annualRaise;` ? if you use Visual Studio try to run the program with `Ctrl`+`F5` to prevent the output console from closing upon program end. – Shadi Apr 01 '18 at 19:52