如果满足嵌套条件,计算结果不显示结果 C++

if nested condition is met, calculate results not showing results C++

我希望程序显示第 1、2、3 年的年度加薪。

用户输入年份 用户输入年薪,

那么如果条件成立,计算如下。

但是当我 运行 它没有显示我输入的任何给定年份的计算结果。为什么?我回去了几次并试图确定我错过了什么?

#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;
}

==比较不是=加一个cout看结果

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

cout << annualRaise;

您需要添加打印 cout 才能看到您的工作结果:

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