expected primary expression before else?

Im having a problem at the moment. I just finished my program(its still in a very rough draft, I am working out all the kinks) and im having a problem.

I keep getting "expected primary-expression before else" (line 61)

Here is the code...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<iostream>
#include <fstream>
using namespace std;
ifstream infile("in1.dat");
ofstream outfile("out1.txt");
int validtemperature(int,int,int);
int classify(int,int,int);
int findavg(int,int,int);
double whatseason(double);
int main()
{
    
    int num1, num2, num3, result, count_valid=0, count_invalid=0;
    int totalgroups=0;
    bool valid;
    
    if(!infile)
    {
         cout << "unable to open file for reading";
    }    
    
    infile >> num1 >> num2 >> num3;
    while(infile) { // while a value was successfully read
         cout<<num1<<" "<<num2<<" "<<num3<<endl; // process it
         infile>>num1>>num2>>num3; // try to get another value
     }
    
    infile >> num1 >> num2 >> num3;
    while (infile) {
    
    cout << num1 << num2 << num3 <<endl;
    valid=validtemperature(num1,num2,num3);
    if (valid=true){
         cout<<"The set of temperatures is valid";
         count_valid++;
         classify(num1,num2,num3);
    }
    else if(valid=false){
              cout<<"The set of temperatures is invalid";
              count_invalid++;
              }
    totalgroups++;          
    infile >> num1 >> num2 >> num3;
    }
    
    
infile.close();
outfile.close();    
system ("pause");
return 0;
}


//valid temp
int validtemperature(int x,int y,int z){

    bool a,b,c;
    
    if(x>=-10&&x<=105){
         a=true;    
    else
         a=false;
    }
       
    if (y>=-10&&y<=105){
         b=true;
    else 
         b=false;
    }     
    
    if (z>=-10&&z<=105){
         c=true;
    else 
         c=false;
    }     
    
    if (x=true&&y=true&&z=true){
         return true;
    else
         return false;
    }
}
//calssifuy
int classify(int x,int y,int z){
    
    double average;
    
    average=findavg(x,y,z);
    whatseason(average);
    
}

//find avg
int findavg(int x,int y,int z){
    
    double avg;
    
    avg=x+y+z/(double)3;
    return avg;
}

//WHAT SEASON
double whatseason(double x){
       cout<<"The average is "<<x<<endl;
       
       if(x>=100)
            cout<<"It is roasting season";
       else if{x>=80&&x<100)
                 cout<<"It is summer";
       else if{x>=60&&x<80)
                 cout<<"It is spring";
       else if{x>=40&&x<60)
                 cout<<"It is fall";
       else if{x>=0&&x<40)
                 cout<<"It is winter";
       else if(x<0)
                 cout<<"It is freezin' season";
}

What is the problem?
Your syntax.
1
2
3
4
5
6
7
if( condition ){
  a=true;
} //<-- ending the if block
else 
{ //<-- opennig the else block
  a=false;
}
The brackets are not needed for just one statement, and you better just a = condition;

if (x=true&&y=true&&z=true){ = is assignment, == is comparison.
But you are trying to compare an int against a bool. I think that true will translate to 1 in that case, so x == 1 ¿does make sense?
Also you could just return the test.

¿What are a,b,c for?
It makes perfect sense. I just redid it and it works perfectly. thanks a lot. i got rid of a,b,c as they weren't necessary.
Topic archived. No new replies allowed.