Hello. I cannot get the speed in line 27 to apply to the choices that follow. I thought that if the cin>>speed was included within the larger brackets, then it would automatically apply to any sub-brackets within...Help please?
#include <iostream>
usingnamespace std;
int main()
{
char code;
int fee;
int speed;
char type;
cout<<"Please enter 'V' for visitor, 'F' for faculty/staff, or 'S' for student.\n";
cin>>code;
if (code=='V'||code=='v')
{
fee=120;
cout<<"Fee is $120.00\n";
}
elseif (code=='F'||code=='f')
{
fee=75;
cout<<"Fee is $75.00\n";
}
elseif (code=='S'||code=='s')
{
cout<<"Please enter speed you were going at time of ticket.\n";
cin>>speed;
cout<<"Enter '1' if you are a senior, or '2' if not.\n";
cin>>type;
if (type=='1')
{
if (41<=speed<=55)
{
fee=212.5;
cout<<"Fee is $212.50\n";
}
elseif (speed>55)
{
fee=362.5;
cout<<"Fee is $362.60\n";
}
else
{
fee=125;
cout<<"Fee is $125.00\n";
}
}
else
{
if (speed>40)
{
fee=162.50;
cout<<"Fee is $162.50\n";
}
else
{
fee=75;
cout<<"Fee is $75.00\n";
}
}
}
return 0;
}
Is your program:
1) Not compiles
* Is other code compiles correctly, i. e. is your compiler configured properly?
* If it is, give us error message and corresponding code part.
2) Not running
* Are you sure that it is not a problem with automatically closing console?
* How do you run it?
* Is there any error messages?
3) Gives an error when run
* Is it system error message or error reported in console?
* Give us error message and input which leads to error.
4) Not giving correct results
* Tell what you entered, what you expected, and what you got.
* Are you sure that results you expected are correct?
if (41<=speed<=55) is always true: 41<=speed can evaluate either to true or false, which can be converted to 1 or 0 respectively. (0 or 1) <= 55 is always true.
So no matter what speed you enter, you will always get fine of 212.5.
@noahfrere posted literally 1 minute after you, could have even been 1 second after you, it doesnt show specifically. He probably pressed reply before your answer even existed.
Edit: Whoops thought noah was just other dude and not the OP :D