-
|| or starements
hey only in 4th week of learning c++ just wanted to know what this error message means for this program, i am using dev c++ as a compiler:
Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double answer = 0, userinput = 0, convertback = 0;
int convert =0, modcon = 0, modcon1 = 0, wholenum = 0, cents = 0, cents1 = 0;
cout << setiosflags(ios::fixed);
cout << setiosflags(ios::showpoint);
cout << setprecision(2);
cout<<"Please enter a sum of money and i will round it to the nearest 5 cents for you: ";
cin>>userinput;
convert =(int)(userinput*100);
modcon =(convert%100);
wholenum =(convert-modcon);
modcon1 =(modcon%10);
if (modcon1 >= 3 || <=7)
{
modcon1 =((modcon/5 + 1)*5);
}else if (modcon1 <=2 || >=8)
{
modcon1 =((modcon/5)*5);
}
cents =(modcon-modcon1);
cents1 =(cents+modcon1);
convertback =(double)(wholenum+cents1);
answer =(convertback/100);
cout<<"The Answer is: "<<endl;
return 0;
}
error saying - expected primary-expression before '<=' token
appeared for || or statement, sorry if i dodnt give enough info here or something but i think thats all you need.....
thnx in advance and i know its not finished yet
-
Code:
if (modcon1 >= 3 || modcon1 <=7)
Kurt
Edit: but then this is alwais true
-
haha thnx just needed to enter name after || or statement
-
You'll need && if you want to check if modcon is in range 3...7 (both conditions must be true).
And if you fix this
Code:
if (modcon1 >= 3 && modcon1 <= 7) {
...
}
else if (modcon1 <= 2 || modcon1 >= 8) {
...
}
the red part becomes redundant: if the program execution gets to the else part, this condition will always be true.