if statement - C++ if-else if Issues -



if statement - C++ if-else if Issues -

i'm having issues programme below. should convert numbers between 1-100 aa,ba,bb,cb,cc,d,f. stops working , shows "ba" if come in number less 84. checked code. don't understand problem.

#include <iostream> using namespace std; int main() { int secenek,notu; cout << "not dönüştürücü" << endl; cout<<"başlamak için 1'e basın:\n"; cin>>secenek; if (secenek==1) { cout<<"dönüştürülecek not: "; cin>>notu; } if (notu<0 || notu>100) { cout<<"geçerli bir not girin.\n"; } else if (notu>=90) { cout<<"aa"; } else if (notu<90 || notu>84) { cout<<"ba"; } else if (notu<85 || notu>79) { cout<<"bb"; } else if (notu<80 || notu>74) { cout<<"cb"; } else if (notu<75 || notu>69) { cout<<"cc"; } else if (notu<70 || notu>59) { cout<<"d"; } else if (notu<60) { cout<<"f"; } }

you made logical error:

else if (notu<90 || notu>84)

should be

else if (notu<90 && notu>84)

and same goes next conditions.

edit @jarod42 suggested; don't need check notu<90 anymore... code this:

if (notu<0 || notu>100) { cout<<"geçerli bir not girin.\n"; } else if (notu>=90) { cout<<"aa"; } else if (notu>84) { cout<<"ba"; } else if (notu>79) { cout<<"bb"; } etc...

c++ if-statement

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -