Else if problem! Help!

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
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
    float test, quiz, home, grade; 
    int choice;
    cout << "Welcome to the tutorial program. What would you like to know?\n\n";
    cout << "     1. What is my current grade?\n";
    cout << "     2. Info about the program.\n\n";
    cout << "Please enter your choice: ";
    
    cin >> choice;
    cout << "\n\n\n\n";
    
    if(choice == 1)          
         cout << "You have chosen program number one.\n\n";
              
         cout << "Please enter your average test score: ";
         cin >> test;
              
         cout << "\nPlease enter your average quiz score: ";
         cin >> quiz;
              
         cout << "\nPlease enter your average homework score: ";
         cin >> home;
              
         grade = (test * .5) + (quiz * .4) + (home * .1)/3;
   
         cout << "\n\nYour current grade is: " << grade << "%";
    
    else if(choice == 2)     
         cout << "This program was created by Mitchell DeJonghe.\n";
         cout << "Created using Dev-C++ 4.9.9.2.\n";
         cout << "Date Created :10/24/11\n";
         cout << "Date Updated: 10/24/11\n\n";              

    else(choice > 2)            
         cout << "Invalid choice";             
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

I'm getting the "expected primary-expression before else" error on lines 35 and 41. Whats the problem?
Last edited on
you forgot grouping symbols, you know { }.

Your code would read like if you had them:
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
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
    float test, quiz, home, grade; 
    int choice;
    cout << "Welcome to the tutorial program. What would you like to know?\n\n";
    cout << "     1. What is my current grade?\n";
    cout << "     2. Info about the program.\n\n";
    cout << "Please enter your choice: ";
    
    cin >> choice;
    cout << "\n\n\n\n";
    
    if(choice == 1)
    {          
         cout << "You have chosen program number one.\n\n";
              
         cout << "Please enter your average test score: ";
         cin >> test;
              
         cout << "\nPlease enter your average quiz score: ";
         cin >> quiz;
              
         cout << "\nPlease enter your average homework score: ";
         cin >> home;
              
         grade = (test * .5) + (quiz * .4) + (home * .1)/3;
   
         cout << "\n\nYour current grade is: " << grade << "%";
    }
    else if(choice == 2)
    {
         cout << "This program was created by Mitchell DeJonghe.\n";
         cout << "Created using Dev-C++ 4.9.9.2.\n";
         cout << "Date Created :10/24/11\n";
         cout << "Date Updated: 10/24/11\n\n";              
    }
    else   // (choice > 2) not required... and not right...  
    {        
         cout << "Invalid choice";             
    }
    system("PAUSE");
    return EXIT_SUCCESS;
}


Let see if that helps you out.
Worked like a charm! Thanks!
Topic archived. No new replies allowed.