vendredi 27 octobre 2017

If/Else statement doesn't work properly in c++

I'm a newbie programmer and I had a problem with if/else statement in my code. the first and the second conditions work pretty well, but the last "else",which is supposed to return the main input(the entered "n") without any change, returns incorrect answer. where is the problem? The code is below:

#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
if (n>3000000){
 n=n*0.9;
 cout<<n;

}//if

else if (2000000<n<3000000){
n=n*0.95;
n=n*0.97;
cout<<n;

}//if

else
cout<<n;
return 0;
}//int

Aucun commentaire:

Enregistrer un commentaire