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

Getting syntax error. ...

P: 1
Getting syntax error. ...
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5.  int c,n;
  6.  clrscr();
  7.  cout<<"xyz cofee shop"<<endl<<"1cup=rs10"<<"to buy enter money"<<endl;
  8.  cin>>n;
  9.  cout<<"you have entered"<<n;
  10.  if(n%10==0)
  11.  {
  12.  cout<<"enter the no of cups"<<endl;
  13.  cin>>c;
  14.  }
  15.  else
  16.  cout<<"enter amount in multiple of 10";
  17.  if(c==1)&& if(n==10)
  18.  {
  19.  cout<<"here is your cofee";
  20.   }
  21.  if(c==2)&& if(n==10)
  22.  {
  23.  cout<<"sorry more money req.";
  24.  }
  25.  if(c==3)&& if(n==40)
  26.  cout<<"refunded money is"<<n-10;
  27.  getch();
  28.  }
Aug 4 '17 #1
Share this Question
Share on Google+
3 Replies


Frinavale
Expert Mod 5K+
P: 9,731
At first glance I noticed that your your if statements are incorrect.

You shouldn't have an operator like "&&" between two if statements like you have (for example):
Expand|Select|Wrap|Line Numbers
  1. if(c==2)&& if(n==10)
The above example should be:
Expand|Select|Wrap|Line Numbers
  1. if(c==2 && n==10)
Also, it may help if you attempted proper indentation so that you are fully aware of the start and ends of if statement blocks... to avoid other syntax errors use open and close curly braces to indicate where your if blocks start and end.

For example, your if statements should be structured:
Expand|Select|Wrap|Line Numbers
  1. if(*condition*)
  2. {
  3.   //code
  4. }
  5. else
  6. {
  7.   //code
  8. }
There may be other problems, but I recommend starting with correcting your if statements.
Aug 4 '17 #2

Expert 100+
P: 2,398
It always helps if you provide the precise wording of any warning or error messages.
Aug 7 '17 #3

Expert 100+
P: 2,398
If n is a multiple of 10, then you will reach line 17 without assigning a value to c.
Aug 7 '17 #4

Post your reply

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