Problem with IF and ELSE Statements | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Problem with IF and ELSE Statements

Hello, Someone can tell me what is the problem with this code because , if i enter the values : 1) ora = 4 , minut = 0; Displays me the correct value ( nrb = ora) 2) ora = 4 , minut = 30 Displays me the same value like above which is incorrect. 3) ora = 4 , minut = 22 Displays me the same value like above which is incorrect. I don't know what is the problem. Please help me with this . Thanks. This is the code. #include <iostream> using namespace std; int main() { float ora , minut , nrb; cout << "Va rugam sa introduceti o ora"; cin >> ora; cout << "Va rugam sa introduceti si un minut"; cin >> minut; if(minut == 0){ nrb = ora; } else if(minut == 30){ nrb = 5; } else { nrb = 0; } cout << "Numarul de batai este egal cu "<< ora; return 0; }

14th Oct 2019, 7:40 PM
Joita Vladut
Joita Vladut - avatar
1 Answer
+ 2
In the cout<< "Numarul de batai este egal cu "<< ora; replace ora with nrb, if its ora it'll just print the user input and not the changed variable.
14th Oct 2019, 7:45 PM
Odyel
Odyel - avatar