this is the error i am getting: Error2 error C2181: illegal else without matching if
this is me code:
#include %26lt;iostream%26gt;
using namespace std;
using std::cout;
using std::cin;
using std::endl;
int main()
{
//declare variables
int people = 1;
int fee = 0;
int totalpeople = 0;
int totalfee = 0;
while(people %26gt; 0)
{
cout %26lt;%26lt; "Enter number of registrants for this company (Enter 0 to exit): " %26lt;%26lt; endl;
cin %26gt;%26gt; people;
if(people %26gt;= 1 %26amp;%26amp; people %26lt;= 3)
{
fee = 150;
}
else if(people %26gt;= 4 %26amp;%26amp; people %26lt;= 9);
{
fee = 100;
}
else
{
fee = 90;
}
totalpeople += people;
totalfee += (people * fee);
}
cout %26lt;%26lt; "Total people attending: " %26lt;%26lt; totalpeople %26lt;%26lt; endl;
cout %26lt;%26lt; "Total fee collected: " %26lt;%26lt; totalfee %26lt;%26lt; endl;
cout %26lt;%26lt; "Average fee per person: " %26lt;%26lt; totalfee / totalpeople %26lt;%26lt; endl;
return 0;
}
How do you fix this error in C++ or how would you rewrite this code?
Delete the semi-colon at the end of this line:
else if(people %26gt;= 4 %26amp;%26amp; people %26lt;= 9);
to take care of the compile error. Your logic is ok.
I doubt you need these lines:
using std::cout;
using std::cin;
using std::endl;
'using namespace std' should be all you need.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment