Need help with this program about the presidential poll

Here is the description of my program:

Election Polling: Write a utility program that reads:
the name of a state (example: new_york)
the poll A's numbers for romney and obama (example: 562 521 108) (the third number is "undecided"
the poll B's numbers for romney and obama (example: 674 754 84)

So an input line looks like:
    new_jersey     400 300 100     60 35 5

The program prints a line like this:      new_jersey:   37%   50%  ///  35%   60%  ///   36%   55%  BLUE


The first two percentages are the romney and obama percentages of poll A.
The second two percentages are the romney and obama percentages of poll B.
The third two percentages are the averages of the romney and obama percentages of polls A and B.


All percentages are calculated and written as integers.

The color is printed according to the spread of the averages:
differ by 1% or less: WHITE
romney leads by more than 1% but less than 8%: PINK
romney leads by 8% or more: RED
obama leads by more than 1% but less than 8%: LIGHT BLUE
obama leads by 8% or more: BLUE


Here is the program that I wrote:
#include <iostream>
#include <string>
using namespace std;

int main() {
string city;
string color, PINK, RED, LIGHT BLUE, BLUE, WHITE;
int pollA1,pollA2,pollA3,pollB1,pollB2,pollB3,RPA,OPA,RPB,OPB,RA,OA;

cin >> city >> pollA1 >> pollA2 >> pollA3 >> pollB1 >> pollB2 >> pollB3;

RPA = pollA1 / (pollA1+pollA2+pollA3);
OPA = pollA2 / (pollA1+pollA2+pollA3);
RPB = pollB1 / (pollB1+pollB2+pollB3);
OPB = pollB2 / (pollB1+pollB2+pollB3);
RA = (pollA1 + pollB1)/ 2;
OA = (pollA2 + pollB2)/ 2;


if (RA > OA && 1 < (RA-OA) && (RA-OA) < 8)
color = PINK;
else if (RA > OA && (RA-OA)>= 8)
color = RED;
else if (OA > RA && 1 < (OA-RA)) && (OA-RA)< 8)
color = LIGHT BLUE;
else if (OA > RA && (OA-RA)>=8);
color = BLUE;
else
color = WHITE;

cout << city <<": "<<RPA<<"% "<<OPA<<"% /// "<<RPB<<"% "<<OPB<<"% /// "<<RA<<"% "<<OA<<"% "<<color<<endl;

system("pause");
return 0;

}

Here is the errors that the Dev C++ compiler gave me, and I don't know how to fix it at all, Please help !!!

C++.cpp: In function `int main()':
C++.cpp:7: error: expected init-declarator before "BLUE"
C++.cpp:7: error: expected `,' or `;' before "BLUE"
C++.cpp:24: error: expected identifier before '(' token
C++.cpp:24: error: expected `;' before '(' token
C++.cpp:27: error: `BLUE' undeclared (first use this function)
C++.cpp:27: error: (Each undeclared identifier is reported only once for each function it appears in.)
C++.cpp:28: error: expected primary-expression before "else"
C++.cpp:28: error: expected `;' before "else"
The diagnostics are telling you want you need to fix.

Line 7: The compiler doesn;t recognize the token preceding BLUE. C++ identifiers can't have spaces in them, therefore LIGHT BLUE is not a valid identifier. LIGHT_BLUE is.

Line 24: You have unbalanced parentheses.
else if (OA > RA && 1 < (OA-RA)) && (OA-RA)< 8)
The second close paren terminates the if condition. The rest of the line is bogus.

Line 27: BLUE is not recognized because of the error in line 7. Fix line 7 and this error will go away.

Line 28: The else is extraneous because of the semicolon on line 26 which terminates the if.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.


Last edited on
Thanks for Anon's help !!! Now the code errors are fixed ! But new problem comes !! When I compile the code, it gives me this result, make me confusing so much !! Please help again !!

Following is the output screen:

new_jersey 400 300 100 60 35 5
new_jersey: 0% 0% /// 0% 0% /// 230% 167%
Press any key to continue . . .
int pollA1,pollA2,pollA3,pollB1,pollB2,pollB3 (should be double)
RPA,OPA,RPB,OPB (should be double)
RA,OA (int)

RPA = pollA1 / (pollA1+pollA2+pollA3)*100;
OPA = pollA2 / (pollA1+pollA2+pollA3)*100;
RPB = pollB1 / (pollB1+pollB2+pollB3)*100;
OPB = pollB2 / (pollB1+pollB2+pollB3)*100;
RA = (pollA1 + pollB1)/ 2;
OA = (pollA2 + pollB2)/ 2;

string color; alone is fine no need to write out the colors
Topic archived. No new replies allowed.