Expected primary expression before...

A simple program - Probably a simple error.

Page 1 of 1

2 Replies - 2121 Views - Last Post: 16 November 2009 - 02:55 PM Rate Topic: -----

#1 TsuriKata   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-November 09

Expected primary expression before...

Posted 16 November 2009 - 02:01 PM

Hey guys, being my first post and all, let me say I'm just now taking an introduction c++ course, and this is a small project that I'm receiving an error in. The program is supposed to take three sides of a triangle and then tell whether it is a right triangle or not. Here is my error within in the code...

 if((side1 * side1 == (side2 * side2 + side3 * side3)) ||
	   (side2 * side2 == (side1 * side1 + side3 * side3)) ||
	   (side3 * side3 == (side1 * side1 + side2 * side2))
	   )
	
	cout << "It's a right triangle.";
	cout << endl; 
	
   
	else 
	cout << "It's not a right triangle.";
	cout << endl; 
	
	return 0;


Compiler says: expected primary-expression before "else"

I've been having problems and fixing most on my own, but why this error?

Is This A Good Question/Topic? 0
  • +

Replies To: Expected primary expression before...

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: Expected primary expression before...

Posted 16 November 2009 - 02:14 PM

The if (and the else) only affects the line immediately following it unless the block of code you want executed is wrapped in {}s.
Was This Post Helpful? 1
  • +
  • -

#3 TsuriKata   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-November 09

Re: Expected primary expression before...

Posted 16 November 2009 - 02:55 PM

View PostJackOfAllTrades, on 16 Nov, 2009 - 01:14 PM, said:

The if (and the else) only affects the line immediately following it unless the block of code you want executed is wrapped in {}s.


Great! I think I got it working. Thanks a ton!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1