# Problem in if else statements (Expected Primary Expresion)

Page 1 of 1

## 3 Replies - 1983 Views - Last Post: 07 October 2008 - 10:12 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=66598&amp;s=53b28c384229e50c818213ad7cfeaab1&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 ryan2506

Reputation: 0
• Posts: 3
• Joined: 07-October 08

# Problem in if else statements (Expected Primary Expresion)

Posted 07 October 2008 - 09:50 AM

```#include <iostream>   //cin, cout
#include <iomanip>	//setw, setprecision, fixed
#include <cmath>	  //pow
#include <fstream>	//ofstream
#include <string>	 //assign strings

using namespace std;  //using the standard names

//function prototype

void InformationScreen();

int main()

{
//variable declarations
int		   reading1,	  //pollen level 1 of city 1
reading2,	  //pollen level 2 of city 1
reading3,	  //pollen level 3 of city 1
reading4,	  //pollen level 1 of city 2
reading5,	  //pollen level 2 of city 2
reading6;	  //pollen level 3 of city 2

float	 pollenlevel1,	  //average of city 1's pollen level
pollenlevel2;	  //average of city 2's pollen level

char	  city1[75],		 //name of city 1
city2[75];		 //name of city 2

string	warnmsg1,		  //stores city1 warning message
warnmsg2;		  //stores city2 warning message

ofstream outputfile;
outputfile.open("lab5report.txt"); //Declare an output file, named lab4report.txt
InformationScreen();	 //this causes the information screen to be displayed

//user input of first city name and pollen levels
cout <<"Enter the name of the city the pollen samples were taken from: " <<endl;
cin.getline(city1,75); //storeing the data inputed into city1
cout <<"Enter the first reading: " <<endl;
cout <<"Enter the second reading: "<<endl;
cout <<"Enter the third reading: "<<endl;

//calculate Average pollen level of city 1

//user input of second city and pollen levels
cout <<"Enter the name of the next city pollen sample were taken from: "<<endl;
cin.ignore();
cin.getline(city2,75); //storeing the data inputed into city2
cout <<"Enter the first reading: " <<endl;
cout <<"Enter the second reading: "<<endl;
cout <<"Enter the third reading: "<<endl;

//calculate Average pollen level of city 2

if (pollenlevel1 > 0 || pollenlevel1 < 10)
{
cout << pollenlevel1 << " is an invalid score.\n";
cout << "Run the program again and make sure the pollen levels for\n";
cout << "city 1 are integer values from 0 to 10.\n";
}
else
{
if (pollenlevel1 <= 0 && pollenlevel1 >= 2.5)
warnmsg1 = "good";
else if (pollenlevel1 < 2.5 && >= 5.0)
warnmsg1 = "caution";
else if (pollenlevel1 < 5.0 && >= 7.5)
warnmsg1 = "warning flag";
else if (pollenlevel1 < 7.5 && >= 10)
warnmsg1 = "pollen action day";
}
if (pollenlevel2 > 0 || pollenlevel2 < 10)
{
cout << pollenlevel2 << " is an invalid score.\n";
cout << "Run the program again and make sure the pollen levels for\n";
cout << "city 2 are integer values from 0 to 10.\n";
}
else
{
if (pollenlevel2 <= 0 && pollenlevel2 >= 2.5)
warnmsg2 = "good";
else if (pollenlevel2 < 2.5 && >= 5.0)
warnmsg2 = "caution";
else if (pollenlevel2 < 5.0 && >= 7.5)
warnmsg2 = "warning flag";
else if (pollenlevel2 < 7.5 && >= 10)
warnmsg2 = "pollen action day";
}

outputfile <<"\tCity"
<<setw(12)<<"ST #1"
<<setw(7) <<"ST #2"
<<setw(7) <<"ST #3"
<<setw(14)<<"POLLEN LEVEL"
<<setw(9) <<"MESSAGE\n"<<endl;

//output data to file lab4report.txt
cout << setprecision( 3 ) << fixed << showpoint;

//output city 1 and data accordingly
outputfile <<left<< setprecision(1)<<fixed<<showpoint
<<setw(15)<<city1
<<setw(12)<<pollenlevel1
<<left<<setw(19)<<warnmsg1<<endl;

//output city 2 and data accordingly
outputfile <<left<< setprecision(1)<<fixed<<showpoint
<<setw(15)<<city2
<<setw(12)<<pollenlevel2
<<left<<setw(19)<<warnmsg2<<endl;

return 0;
}

```

I'm sure I have placement errors among other things but I keep getting (Expected Primary Expression before '>=' token) for everyone of my if else statements.
Also If there is a way to make all the info for city 1 and city 2 in 1 bit If Statement then output at the end. I would like to know how.
Another not We have not discussed Loops or anything farther then what i have in this code in class and I will get in trouble for using it.
So please use the basic methods

Is This A Good Question/Topic? 0

## Replies To: Problem in if else statements (Expected Primary Expresion)

• Saucy!

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

## Re: Problem in if else statements (Expected Primary Expresion)

Posted 07 October 2008 - 09:57 AM

You're missing the pollenlevel1 in the second conditional of those statements:
```else if (pollenlevel1 < 2.5 && pollenlevel1 >= 5.0)
```

### #3 ryan2506

Reputation: 0
• Posts: 3
• Joined: 07-October 08

## Re: Problem in if else statements (Expected Primary Expresion)

Posted 07 October 2008 - 10:03 AM

Man I can not believe I did not see that. I guess thats how it goes. I appreciate your help maybe 1 day I will be able to return the favor for someone else
```#include <iostream>   //cin, cout
#include <iomanip>	//setw, setprecision, fixed
#include <cmath>	  //pow
#include <fstream>	//ofstream
#include <string>	 //assign strings

using namespace std;  //using the standard names

//function prototype

int main()

{
//variable declarations
int		   reading1,	  //pollen level 1 of city 1
reading2,	  //pollen level 2 of city 1
reading3,	  //pollen level 3 of city 1
reading4,	  //pollen level 1 of city 2
reading5,	  //pollen level 2 of city 2
reading6;	  //pollen level 3 of city 2

float	 pollenlevel1,	  //average of city 1's pollen level
pollenlevel2;	  //average of city 2's pollen level

char	  city1[75],		 //name of city 1
city2[75];		 //name of city 2

string	warnmsg1,		  //stores city1 warning message
warnmsg2;		  //stores city2 warning message

ofstream outputfile;
outputfile.open("lab5report.txt"); //Declare an output file, named lab4report.txt
InformationScreen();	 //this causes the information screen to be displayed

//user input of first city name and pollen levels
cout <<"Enter the name of the city the pollen samples were taken from: " <<endl;
cin.getline(city1,75); //storeing the data inputed into city1
cout <<"Enter the first reading: " <<endl;
cout <<"Enter the second reading: "<<endl;
cout <<"Enter the third reading: "<<endl;

//calculate Average pollen level of city 1

//user input of second city and pollen levels
cout <<"Enter the name of the next city pollen sample were taken from: "<<endl;
cin.ignore();
cin.getline(city2,75); //storeing the data inputed into city2
cout <<"Enter the first reading: " <<endl;
cout <<"Enter the second reading: "<<endl;
cout <<"Enter the third reading: "<<endl;

//calculate Average pollen level of city 2

if (pollenlevel1 > 0 || pollenlevel1 < 10)
{
cout << pollenlevel1 << " is an invalid score.\n";
cout << "Run the program again and make sure the pollen levels for\n";
cout << "city 1 are integer values from 0 to 10.\n";
}
else
{
if (pollenlevel1 <= 0 && pollenlevel1 >= 2.5)
warnmsg1 = "good";
else if (pollenlevel1 < 2.5 && pollenlevel1 >= 5.0)
warnmsg1 = "caution";
else if (pollenlevel1 < 5.0 && pollenlevel1 >= 7.5)
warnmsg1 = "warning flag";
else if (pollenlevel1 < 7.5 && pollenlevel1 >= 10)
warnmsg1 = "pollen action day";
}
if (pollenlevel2 > 0 || pollenlevel2 < 10)
{
cout << pollenlevel2 << " is an invalid score.\n";
cout << "Run the program again and make sure the pollen levels for\n";
cout << "city 2 are integer values from 0 to 10.\n";
}
else
{
if (pollenlevel2 <= 0 && pollenlevel2 >= 2.5)
warnmsg2 = "good";
else if (pollenlevel2 < 2.5 && pollenlevel2 >= 5.0)
warnmsg2 = "caution";
else if (pollenlevel2 < 5.0 && pollenlevel2 >= 7.5)
warnmsg2 = "warning flag";
else if (pollenlevel2 < 7.5 && pollenlevel2 >= 10)
warnmsg2 = "pollen action day";
}

outputfile <<"\tCity"
<<setw(12)<<"ST #1"
<<setw(7) <<"ST #2"
<<setw(7) <<"ST #3"
<<setw(14)<<"POLLEN LEVEL"
<<setw(9) <<"MESSAGE\n"<<endl;

//output data to file lab4report.txt
cout << setprecision( 3 ) << fixed << showpoint;

//output city 1 and data accordingly
outputfile <<left<< setprecision(1)<<fixed<<showpoint
<<setw(15)<<city1
<<setw(12)<<pollenlevel1
<<left<<setw(19)<<warnmsg1<<endl;

//output city 2 and data accordingly
outputfile <<left<< setprecision(1)<<fixed<<showpoint
<<setw(15)<<city2
<<setw(12)<<pollenlevel2
<<left<<setw(19)<<warnmsg2<<endl;

return 0;
}

```

This post has been edited by ryan2506: 07 October 2008 - 10:14 AM

### #4 ryan2506

Reputation: 0
• Posts: 3
• Joined: 07-October 08

## Re: Problem in if else statements (Expected Primary Expresion)

Posted 07 October 2008 - 10:12 AM

Hmmm now I'm having a problem where it outputs the heading and all the data and average but not the warning message. Like its not being stored or I am calling it to output in the wrong place.