GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Feb-2009, 09:08
kimmp kimmp is offline
New Member
 
Join Date: Feb 2009
Posts: 1
kimmp is on a distinguished road

Error: expected primary-expression before ‘||’ token


CPP / C++ / C Code:

#include<iostream>

using namespace std;

enum triangles {NOTRIANGLE, EQUILATERAL, ISOSCELES, SCALENE};

void getLengths (int side1, int side2, int side3, int side4);
void determineShape (int side1, int side2, int side3, int side4);
void displayShape (int side1, int side2, int side3, int side4, triangles shape);





void determineShape (int side1, int side2, int side3, int side4)
{
	char typeOf;
	triangles shape;
	
        if (side4 > 0) 
            shape = NOTRIANGLE; 
        else if (side1 == side2  && side2 == side3) 
            shape = EQUILATERAL;
        else if (side1 == side2 && side2 != side3) || (side2 == side3 && side1 != side3) || (side1 == side3 && side2 != side1);
            shape = ISOSCELES;
        else (side1 != side2 != side3);
         shape = SCALENE; 
	
	
}


I have to write a program to determine the type of triangle based upon the side lengths.
I cut out most of the program, other than to make sure I did everything right up top as well.
Netbeans gives me the following errors:

2.cc:69: error: expected primary-expression before ‘||’ token
ll2.cc:71: error: expected primary-expression before ‘else’
l2.cc:71: error: expected `;' before ‘else’
  #2  
Old 08-Feb-2009, 10:20
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: I'm not quite sure what I am doing wrong


Quote:
Originally Posted by kimmp
CPP / C++ / C Code:

void determineShape (int side1, int side2, int side3, int side4)
{
//...	
        else if (side1 == side2 && side2 != side3) || (side2 == side3 && side1 != side3) || (side1 == side3 && side2 != side1);
            shape = ISOSCELES;
//...	
}


2.cc:69: error: expected primary-expression before ‘||’ token
ll2.cc:71: error: expected primary-expression before ‘else’
l2.cc:71: error: expected `;' before ‘else’
In c/c++, the conditional expression must be contained like this:
Code:
|<----must have parenthesis---->| if ( /* conditional-expression */ )
So, that 'else if' multi-condition needs to be surrounded with parenthesis ( ), like this:
CPP / C++ / C Code:
// not necessary to span the condition multiple lines as done here -- this is only for example.
else if (  (side1 == side2 && side2 != side3) 
        || (side2 == side3 && side1 != side3) 
        || (side1 == side3 && side2 != side1) 
      )
  {
            shape = ISOSCELES;
  } 
Also, do not place a semi-colon at the condition's end.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 08-Feb-2009, 10:36
zalezog zalezog is offline
Junior Member
 
Join Date: Oct 2007
Posts: 33
zalezog will become famous soon enough

Re: I'm not quite sure what I am doing wrong


Quote:
CPP / C++ / C Code:

#include<iostream>

using namespace std;

enum triangles {NOTRIANGLE, EQUILATERAL, ISOSCELES, SCALENE};

void getLengths (int side1, int side2, int side3, int side4);
void determineShape (int side1, int side2, int side3, int side4);
void displayShape (int side1, int side2, int side3, int side4, triangles shape);





void determineShape (int side1, int side2, int side3, int side4)
{
	char typeOf;
	triangles shape;
	
        if (side4 > 0) 
            shape = NOTRIANGLE; 
        else if (side1 == side2  && side2 == side3) 
            shape = EQUILATERAL;
        else if  (side1 == side2 && side2 != side3) || (side2 == side3 && side1 != side3) || (side1 == side3 && side2 != side1) ;//What's the semicolon for?
                                                        //You also need a bracket .
            shape = ISOSCELES;
        else (side1 != side2 != side3);//Same here,also You don't need an
                                                            //expression after else.  
         shape = SCALENE; 
	
	
}


Something like this..
CPP / C++ / C Code:
#include<iostream>

using namespace std;

enum triangles {NOTRIANGLE, EQUILATERAL, ISOSCELES, SCALENE};

void getLengths (int side1, int side2, int side3, int side4);
void determineShape (int side1, int side2, int side3, int side4);
void displayShape (int side1, int side2, int side3, int side4, triangles shape);





void determineShape (int side1, int side2, int side3, int side4)
{
	char typeOf;
	triangles shape;
	
        if (side4 > 0) 
            shape = NOTRIANGLE; 
        else if (side1 == side2  && side2 == side3) 
            shape = EQUILATERAL;
        else if ( 
(side1 == side2 && side2 != side3) 
|| (side2 == side3 && side1 != side3) 
|| (side1 == side3 && side2 != side1) 
)
            shape = ISOSCELES;
        else          
       shape = SCALENE; 
	
	
}

 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to read BMP files, header information is wrong / offset Algar C++ Forum 5 24-Feb-2008 04:00
What's wrong with my Linked list program? jpxtreme C Programming Language 1 21-Sep-2006 12:46
what is wrong on this line djd@n MySQL / PHP Forum 3 05-Nov-2005 00:25
Problem with if statement (was: what is wrong???) rubenryhan C Programming Language 2 02-May-2005 09:09
Functions and Classes - Where did I go wrong? redmage C++ Forum 5 10-Apr-2005 19:31

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:04.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.