LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-29-2005, 11:38 PM   #1
lmvent
LQ Newbie
 
Registered: Sep 2005
Posts: 24

Rep: Reputation: 15
c++ syntax error...HELP!!


red% g++ assignment2a.cpp
assignment2a.cpp: In function 'int main()':
assignment2a.cpp:33: syntax error before '{' token
assignment2a.cpp: At global scope:
assignment2a.cpp:37: syntax error before '<<' token
assignment2a.cpp:44: syntax error before '<<' token

my code is

#include <iostream>

using namespace std;

int main(void)
{ int i1, i2, small, big;
cout << "Input the 1st integer: ";
cin >> i1;
if (i1 < 0)
{ cout << "Input must be non-negative. Try again!\n";
return 1;
}
cout << "Input the 2nd integer: ";
cin >> i2;
if (i2 < 0)
{ cout << "Input must be non-negative. Try again!\n";
return 1;
}
if (i1 == i2)
{ cout << "The two numbers are the same!\n";
big = i1;
small = i2;
}
else
{ if (i1 > i2)
{ big = i1;
small = i2;
}
else (i1 < i2)
{ big = i2;
small = i1;
}
}
cout << "The bigger number is" << big << ", the smaller number is" << small << "\n";
if (small == 0)
{ cout << "The smaller number is 0, so no ratio is calculated,";
}
else
{ cout << "The ratio is" << big/small << ", ";
}
cout << "the quadrature sum is" << big*big + small*small << "\n";
if (big%small == 1)
{ cout << small << "is not a perfect divisor of" << big << "\n";
}
else
{ cout << small << "is a perfect divisor of" << big << "\n";
}
return 0;
}


what am i doing wrong??
 
Old 09-30-2005, 12:44 AM   #2
ashucool83
LQ Newbie
 
Registered: Sep 2005
Posts: 11

Rep: Reputation: 0
I think this is the problem :-

else (i1 < i2)
{ big = i2;
small = i1;
}

replace the above code with:-

else if (i1 < i2)
{ big = i2;
small = i1;
}


ALL Comparions DO NEED an "if" ... i hope it compiles for you. It did for me.
 
Old 09-30-2005, 08:51 AM   #3
lmvent
LQ Newbie
 
Registered: Sep 2005
Posts: 24

Original Poster
Rep: Reputation: 15
THANKS SO MUCH!!!! I can't believe I missed that!
 
Old 09-30-2005, 02:40 PM   #4
ashucool83
LQ Newbie
 
Registered: Sep 2005
Posts: 11

Rep: Reputation: 0
No Probs .. these are the errors that take a lot of time. Make sure you keep you code indented . its easy to look for such errors
Thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax error in C ++ mshinska Programming 3 10-07-2005 04:53 PM
Many errors when 'make'ing (example: error: syntax error before `::' token) darkblade Linux - Software 5 03-02-2005 03:00 PM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM
Where's the syntax error tamtam Programming 2 07-24-2004 09:07 AM
ERROR running make when installing Nvidia drivers (syntax error) randyriver10 Linux - Software 5 02-21-2004 04:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration