Expected primary expression?

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
#include <iostream>

using namespace std;

int main()
{
    int currentparagon;
    int desiredparagon;
    int paragonxp;
    int difference;

    cout << "What is your current paragon level: ";
    cin>> currentparagon; //Gets current paragon
    cout << endl;
    cout << "What is your desired paragon level: ";
    cin>> desiredparagon;
    cin.ignore(2);

    if (desiredparagon <= 60); {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 1440000 + 7200000);
    }
    else if ( desiredparagon  >= 61 && <= 71); {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 2880000 + 7200000);
    }
    else if ( desiredparagon >= 72 && <= 80 ) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 5040000 + 7200000);
    }
    else if ( desiredparagon >= 81 && <= 90 ) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 6480000 + 7200000);
    }
    else if ( desiredparagon >= 81 && <= 90 ) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 8640000 + 7200000);
        return 0;
    }



Im getting the error:
1
2
3
4
5
6
7
8
9
10
C:\Users\SpencerXZX.marge-HP\Desktop\Paragon Xp\main.cpp||In function 'int main()':|
C:\Users\SpencerXZX.marge-HP\Desktop\Paragon Xp\main.cpp|23|error: 'else' without a previous 'if'|
C:\Users\SpencerXZX.marge-HP\Desktop\Paragon Xp\main.cpp|23|error: expected primary-expression before '>=' token|
C:\Users\SpencerXZX.marge-HP\Desktop\Paragon Xp\main.cpp|23|error: expected primary-expression before '<=' token|
C:\Users\SpencerXZX.marge-HP\Desktop\Paragon Xp\main.cpp|27|error: 'else' without a previous 'if'|
C:\Users\SpencerXZX.marge-HP\Desktop\Paragon Xp\main.cpp|27|error: expected primary-expression before '<=' token|
C:\Users\SpencerXZX.marge-HP\Desktop\Paragon Xp\main.cpp|31|error: expected primary-expression before '<=' token|
C:\Users\SpencerXZX.marge-HP\Desktop\Paragon Xp\main.cpp|35|error: expected primary-expression before '<=' token|
C:\Users\SpencerXZX.marge-HP\Desktop\Paragon Xp\main.cpp|39|error: expected '}' at end of input|
||=== Build finished: 8 errors, 0 warnings (0 minutes, 0 seconds) ===|
remove the semicolon from line 19 & 23.

Always put an else clause after the last else if, so it catches any error situations.
Last edited on
So, like this?

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
#include <iostream>

using namespace std;

int main()
{
    int currentparagon;
    int desiredparagon;
    int paragonxp;
    int difference;

    cout << "What is your current paragon level: ";
    cin>> currentparagon; //Gets current paragon
    cout << endl;
    cout << "What is your desired paragon level: ";
    cin>> desiredparagon;
    cin.ignore(2);

    if (desiredparagon <= 60) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 1440000 + 7200000);
    }
    else if ( desiredparagon  >= 61 && <= 71) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 2880000 + 7200000);
    }
    else if ( desiredparagon >= 72 && <= 80 ) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 5040000 + 7200000);
    }
    else if ( desiredparagon >= 81 && <= 90 ) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 6480000 + 7200000);
    }
    else ( desiredparagon >= 81 && <= 90 ) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 8640000 + 7200000);
        return 0;
    }


Im just learning, so Im not sure what you mean by an "else clause"

even with that Im still getting:
1
2
3
4
5
6
7
C:\Users\SpencerXZX.marge-HP\Desktop\Paragon Xp\main.cpp||In function 'int main()':|
C:\Users\SpencerXZX.marge-HP\Desktop\Paragon Xp\main.cpp|23|error: expected primary-expression before '<=' token|
C:\Users\SpencerXZX.marge-HP\Desktop\Paragon Xp\main.cpp|27|error: expected primary-expression before '<=' token|
C:\Users\SpencerXZX.marge-HP\Desktop\Paragon Xp\main.cpp|31|error: expected primary-expression before '<=' token|
C:\Users\SpencerXZX.marge-HP\Desktop\Paragon Xp\main.cpp|35|error: expected primary-expression before '<=' token|
C:\Users\SpencerXZX.marge-HP\Desktop\Paragon Xp\main.cpp|39|error: expected '}' at end of input|
||=== Build finished: 5 errors, 0 warnings (0 minutes, 0 seconds) ===|
Last edited on
Im just learning, so Im not sure what you mean by an "else clause"


http://www.cplusplus.com/doc/tutorial/control/


There is lots of reference info, articles & stuff have a look at the top left of this page.

I meant this:

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
if (desiredparagon <= 60) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 1440000 + 7200000);
    }
    else if ( desiredparagon  >= 61 && <= 71) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 2880000 + 7200000);
    }
    else if ( desiredparagon >= 72 && <= 80 ) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 5040000 + 7200000);
    }
    else if ( desiredparagon >= 81 && <= 90 ) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 6480000 + 7200000);
    }
    else if ( desiredparagon >= 81 && <= 90 ) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 8640000 + 7200000);
        return 0;
    }
    else {
         //an error of some type do something to fix it
    }
}


An else cannot have a condition.

I still cant fix the "expected primary-expression" error.

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
#include <iostream>

using namespace std;

int main()
{
    int currentparagon;
    int desiredparagon;
    int paragonxp;
    int difference;

    cout << "What is your current paragon level: ";
    cin>> currentparagon; //Gets current paragon
    cout << endl;
    cout << "What is your desired paragon level: ";
    cin>> desiredparagon;
    cin.ignore(2);

    if (desiredparagon <= 60) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 1440000 + 7200000);
    }
    else if ( desiredparagon  >= 61 && <= 71) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 2880000 + 7200000);
    }
    else if ( desiredparagon >= 72 && <= 80 ) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 5040000 + 7200000);
    }
    else if ( desiredparagon >= 81 && <= 90 ) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 6480000 + 7200000);
    }
    else if ( desiredparagon >= 81 && <= 90 ) {
        difference = (desiredparagon - currentparagon);
        paragonxp = (difference * 8640000 + 7200000);
        return 0;
    }
    else {
        cout<< "Error! Please try again.";
    }

    }
else if ( desiredparagon >= 61 && <= 71) {

These kinds of statements don't make sense in C++. You need to put a valid statement on both sides of the &&:

else if ( desiredparagon >= 61 && desiredparagon <= 71) {
Thanks! That helped a lot.
Topic archived. No new replies allowed.