Help with else if statement!

Hi! !'ve been having a problem regarding the else if statement...
line 15:head suspect
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <ctime>
#include <string>
int main()
{
    using namespace std;
    srand(time(NULL));
    short int iScore;
    short int eScore;
    iScore=0;//your score
    eScore=0;//opponent score
    short int iType;
    short int eType;
    double rundor;//amount of rounds
    string stensaxpase;
    cout<<"                        *************************\n";
    cout<<"                        *     Sten Sax Pase     *\n";
    cout<<"                        *************************\n";//"header"
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<"Hur manga rundor?\n";//how many rounds?
    cin>>rundor;
    while (iScore<=rundor && eScore<=rundor);
    {
          eType = rand() / (RAND_MAX / 3 + 1) + 1;
          cout << "Sten sax eller pase?(1=sten,2=sax,3=pase)\n";
          cin>>stensaxpase;
          if ('stensaxpase' == 'sten'||'stensaxpase' == 'Sten');
          {            
               iType=1;
          }
          else if ('stensaxpase' == 'sax'||'stensaxpase' == 'Sax');
          /*  /\/\/\
          problem!("[Warning] character constant too long for its type")
          
          */
          {
               iType=2;
          }
          else if (stensaxpase == "Pase" || stensaxpase == "pase")
          {
               itype=3;
          }
          if (iType == 1);
          {
                    if (eType =1);//sten
                    {
                              cout<< "Lika!";
                    }
                    elseif (eType =2);//sax
                    {
                           cout<<"Du vann rundan!";
                           iScore=iScore+1;
                           cout<<"Du har "<< iScore<<"poang och motstandaren har "<<eScore;
                    }
                    if (eType =3);//påse
                    {
                              cout<< "Du forlorade rundan!;
                              eScore=eScore+1;
                              cout<<"Du har "<< iScore<<"poang och motstandaren har "<<eScore;
                    }
                    else
                    {
                        cout<< "Skriv antingen sten, sax eller pase(med ring över)";
                    }
          
          }
          else if (iType == 2);
          {
               
          }
          else if(iType == 3);
          {
               
          }
          else;
          {
              cout<<"Skriv 1 for sten, 2 för sax eller 3 för pase!";
          }
    }
    
    cin.ignore();
    cin.get();
} 


the else if (text)is the same as the if one... i can't figure out whats wrong, although ive been coding for 3-4 days.
Anyone who is more experienced?
It's a rock paper scissors game.
rock=sten in code paper=påse(or pase) and scissor=sax
(BTW first time in any forum for me, so tell me if i did something wrong ;P)
Last edited on
 
else if ('stensaxpase' == 'sax'||'stensaxpase' == 'Sax');

There are two problems with line 35.

1) You need to use double quotes (") for string literals. Single quotes (') are for character literals.
2) Remove the semicolon at the end of the line. That terminates the then portion of the if statement.


Thank you SOOO very much!
...
this is the correct code then?
 
else if ("stensaxpase" == "sax"||"stensaxpase" == "Sax")

and how comes it worked with the if statement if thats the case?

Edit: Did NOT work, will you link the code?

My english aint perfect so i couldn't understand what you meant... ;P
Last edited on
"stensaxpase" is a string literal, not a variable.
stensaxpase is a variable.

Also you're missing a quote here: cout<< "Du forlorade rundan!;
line 53 put a space between else and if
line 59 add else before if, maybe. that depends on what you want it to be.
giving up... the user will say 1,2 or 3 instead... ;(
Topic archived. No new replies allowed.