at the moment i have 2 answers to queations and the answers are 1,2,3 or 4 but i ow have to make it so the user has to put a work in like "Brazil" but i try to do the same as if the user puts "A" in and it dosnt work, do i need to change the class type of the answer?

and on dev cpp it says
[Warning] comparison is always false due to limited range of data type

EDIT: it works if i do if (answer_4 == 'brazil') but i put brazil in as the answer and it says the else line.

Edited 6 Years Ago by smitysmit: n/a

char answer_2;
 char answer_3;

system("cls");
        cout << "\n\n\n\t\====QUESTION 2====" << endl;
        cout << "\n\n\n\t\What currency does france use?"<< endl;
        cout << "\n\n\n\t\[1]The dollar" << endl;
        cout << "\n\n\n\t\[2]The great british pound" << endl;
        cout << "\n\n\n\t\[3]The euro" << endl;
        cout << "\n\n\n\t\[4]The yen" << endl;
        cout << "\n\n\n\t\Enter answer here: ";
        cin >> answer_2;
        if ((answer_2 == '3')||(answer_2=='3'))
        {
            system("cls");
            cout << "\n\n\n\t\Well done you got question 2 correct";
        }
           else 
       {
       system ("cls");
       cout << "\n\n\n\t\you got question 2 incorrect";    
        }


Sleep(1000);
        system ("cls");
        cout << "\n\n\n\t\====QUESTION 3====" << endl;
        cout << "\n\n\n\t\What is the capital city of france?" << endl;
        cout << "\n\n\n\t\Enter answer here: ";
        cin >> answer_3;
        if (answer_3 == 'paris')
        {
            system ("cls");
            cout << "\n\n\n\t\well done you got question 3 correct";
        }    
        else
        {
            system("cls");
            cout << "\n\n\n\t\You got question 3 incorrect";
        }

btw it may be badly coded as im new co c++

Edited 6 Years Ago by smitysmit: n/a

use

Code Tag

+ format the text :( & do you have an int main(){}? . + What do you want you program to do

use

Code Tag

+ format the text :( & do you have an int main(){}? . + What do you want you program to do

i juat want to make it so it asks a question "what is the captal of paris" and they the userenters paris and it says "well done you got question 3 correct"

if(answer_3=='paris') is not a correct statement. bkz answer_3 is char and 'paris' is not a char.so u can't get the answer as u expected.

change the answer_3's type as char array instead of char.
use strcmp() function to compare the answer_3 and "paris".
NB: string literals should be within the " not in '.

Edited 6 Years Ago by mn.balakumar: n/a

I don't get it .. Your code ... It doesn't make sense , doesn't compile does nothing .. Here's the real problem ..
1.Using SwitchI will be using Switch statement so i can freely act through rounds and so
2.Making more roundsI will be managing round system using the points integer so if you want more rounds add to the switch :

case x : "Welcome to round X"

Think some people will get mad at me doing this for you.

#include <iostream>

using namespace std;

int answer,points,deb=1;

int main(){
    cout<<"Welcome to my program \n";
    while(deb==1){
        switch (points){
        case 0 :
            cout<<"====QUESTION 1====" << endl;
            cout <<"What currency does france use ?"<< endl;
            cout <<"[1]The dollar" << endl;
            cout <<"[2]The great british pound" << endl;
            cout <<"[3]The euro" << endl;
            cout <<"[4]The yen" << endl;
            cin >> answer;
            if(answer==3){points++;
                cout << "Well done you got question 1 correct"<<endl;
            }
                else deb--;
            break;
        case 1 :
            cout<<"====QUESTION 2====" << endl;
            cout <<"What is the capital of France ?"<< endl;
            cout <<"[1]Paris" << endl;
            cout <<"[2]Mexico" << endl;
            cout <<"[3]China" << endl;
            cout <<"[4]Bucharest" << endl;
            cin >> answer;
            if(answer==1){points++;
                cout << "Well done you got question 2 correct"<<endl;
            }
                else deb--;
            break;
        default : "Rounds Over ! \n";points++;deb--;break;
        }
    }
    cout<<"Game Over . You've got "<<points<<" answers right";
}
This article has been dead for over six months. Start a new discussion instead.