By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,319 Members | 1,963 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,319 IT Pros & Developers. It's quick & easy.

Expression syntax error

P: 1
Hi! I'm new to coding and today I tried to type a code to calculate the electricity bill. And I get this Expression Syntax error in line 56 and 68. Can anybody help me? Thank you. This is my code
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. class electricity
  4. {
  5.     protected:
  6.     float unit;
  7.     float cost;
  8.     public:
  9.     void bill()
  10.     {
  11.         cout<<"\n enter the no. of units"<<endl;
  12.         cin>>unit;
  13.         if(unit<=60)
  14.         {
  15.             if(unit<=30)
  16.             {
  17.             cost=2.5*unit;
  18.             cout<<"cost up to 30 unit is Rs."<<cost<<endl;
  19.             }
  20.             else
  21.             {
  22.                 if(unit<=60)
  23.                 {
  24.                 cost=4.85*unit;
  25.                 cout<<"cost up to 60 unit is Rs."<<cost<<endl;
  26.             }
  27.             else
  28.             {
  29.                 if(unit<=60)
  30.                 {
  31.                     cost=7.85*unit;
  32.                     cout<<"cost up to 60 unti is Rs."<<cost<<endl;
  33.                 }
  34.                 else
  35.                 {
  36.                     if(unit<=90)
  37.                     {
  38.                         cost=10.00*unit;
  39.                         cout<<"cost up to 90 unit is Rs."<<cost<<endl;
  40.                     }
  41.                     else
  42.                     {
  43.                         if(unit<=120)
  44.                         {
  45.                             cost=27.75*unit;
  46.                             cout<<"cost up to 120is Rs."<<cost<<endl;
  47.                         }
  48.                         else
  49.                         {
  50.                         if(unit<=145)
  51.                         {
  52.                         cost=32*unit;
  53.                         cout<<"cost up to 145 units is Rs."<<cost<<endl;
  54.                         }
  55.                         }
  56.                         else
  57.                         {
  58.                         if(unit>180)
  59.                         {
  60.                         cost=45*unit
  61.                         cout<<"Beyond 180 units is Rs."<<cost<<endl;
  62.                         }
  63.                         };
  64.                     }
  65.                 }
  66.             }
  67.         }
  68.             else
  69.         {
  70.             cout<<"BIll amount is Rs."<<cost;
  71.         };
  72.     }
  73. };
  74. void main()
  75. {
  76.     clrscr();
  77.     getch();
  78. }
  79.  
  80.  
Apr 23 '16 #1
Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
You have mismatched and missing braces. Print your code and using a pencil connect every opening brace to its closing brace.

There may be other errors covered up by this one.
Apr 23 '16 #2

Expert 100+
P: 1,035
you cannot use:
if {} else {} else {}
Because it's not obvious when the last 'else' would get executed....

Try finding some info on using 'switch' instead, I would make your code more readable too (I think)
Apr 23 '16 #3

Post your reply

Sign in to post your reply or Sign up for a free account.