My Programme requests two variables: one integer and one float. Both must be greater than 0 and less than 2000. But testing an input of 45 and 0 it is accepting the value and showing the output of 0.00 although the conditions require (cash > 0) && (balance > 0)
.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int cash;
float balance ;
cin >> cash >> balance;
if((cash%5==0) && (cash <= balance) && (cash > 0) && (balance > 0) && (cash <= 2000) && (balance <= 2000))
{
balance = (balance - cash) - 0.50;
cout << fixed;
cout.precision(2);
cout << balance;
}
else if (cash%5 != 0)
{
cout << fixed;
cout.precision(2);
cout << balance;
}
else if (cash > balance)
{
cout << fixed;
cout.precision(2);
cout << balance;
}
return 0;
}
if
. it enters the last, i.e.else if (cash > balance)
. Was this not intented? – default