Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,059 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,558 people online right now. Registration is fast and FREE... Join Now!




Another game i need help with

 
Reply to this topicStart new topic

Another game i need help with

C++ Programmer
18 Jul, 2008 - 08:07 PM
Post #1

New D.I.C Head
*

Joined: 12 Jun, 2008
Posts: 29


My Contributions
Please help, it keeps giving me errors when I compile it, it says the error is where it says getline (firstquestion); Please repost it with this problem fixed, thank you in advance,
CODE
#include<iostream>
#include<string>
using namespace std;

int main(void)
{
    beginning:
    system("CLS");
    system("TITLE Play Game or Load Game?");
    string question1;
    string question2;
    string question3;
    string question4;
    string question5;
    string firstquestion;
    double dpassword;
    system("CLS");
    system("TITLE Test Game");
    cout << "Play Game" << endl;
    cout << "Load Game" << endl;
    cout << "Answer: ";
    getline (firstquestion);
    if(playgameorloadgame == Play Game || Play game || play game){
        goto question1;
    }else if(playgameorloadgame == Load Game || Load game || load game){
        goto loadgame;
    }else{
        cout << "That is invalid" << endl;
        system("PAUSE");
        goto beginning;
    }
    loadgame:
    system("CLS");
    system("TITLE Please enter the password");
    cout << "Please enter the password: " << endl;
    cin >> dpassword;
    if(dpassword == password1){
        goto question1;
    }else if(dpassword == password2){
        goto question2
    }else if(dpassword == password3){
        goto question3
    }else if(dpassword == password4){
        goto question4
    }else if(dpassword == password5){
        goto question5
    }else{
        system("CLS");
        system("TITLE Wrong Password");
        cout << "There are only 5 levels.....for now." << endl;
        system("PAUSE");
        goto beginning;
    }
    question1:
    system("CLS");
    system("TITLE Question 1");
    cout << "What does GPU stand for?" << endl;
    getline (question1);
    if(question1 == Graphics Processing Unit || Graphics Processing unit || Graphics processing unit || graphics processing unit){
        system("CLS");
        system("TITLE Correct!");
        cout << "That is correct, here is the password: password1" << endl;
        cout << "That is not a L that is a one." << endl;
        system("PAUSE");
        goto question2;
    }else{
        system("CLS");
        system("TITLE Wrong Answer");
        cout << "Sorry, that is incorrect." << endl;
        system("PAUSE");
        goto beginning;
    }
    question2:
    system("CLS");
    system("TITLE Question 2");
    cout << "What does CPU stand for?" << endl;
    getline (question2);
    if(question2 == Central Processing Unit || Central Processing unit || Central processing unit || central processing unit){
        system("CLS");
        system("TITLE Correct!");
        cout << "That is correct, here is the password: password2" << endl;
        system("PAUSE");
        goto question3;
    }else{
        system("CLS");
        system("TITLE Wrong Answer");
        cout << "Sorry, that is incorrect." << endl;
        system("PAUSE");
        goto beginning;
    }
    question3:
    system("CLS");
    system("TITLE Question 3" << endl;
    cout << "Can your computer run without a graphics card?" << endl;
    getline (question3);
    if(question3 == yes || Yes){
        system("CLS");
        system("TITLE Correct!");
        cout << "That is correct, here is the password: password3" << endl;
        system("CLS");
        goto question4;
    }else{
        system("CLS");
        system("TITLE Wrong Answer");
        cout << "Sorry, that is incorrect." << endl;
        system("PAUSE");
        goto beginning;
    }
    question4:
    system("CLS");
    system("TITLE Question 4");
    cout << "Does a computer need a processor?" << endl;
    getline (question4);
    if(question4 == yes || Yes){
        system("CLS");
        system("TITLE Correct!");
        cout << "That is correct, here is the password: password4" << endl;
        system("PAUSE");
        goto question5;
    }else{
        system("CLS");
        system("TITLE Wrong Answer");
        cout << "Sorry, that is incorrect." << endl;
        system("PAUSE");
        goto beginning;
    }
    question5:
    system("CLS");
    system("TITLE Question 5");
    cout << "Can you use your T.V. as a monitor?" << endl;
    getline (question5);
    if(question5 == yes || Yes){
        system("CLS");
        system("TITLE Correct!");
        cout << "That is correct, here is the password: password5" << endl;
        system("PAUSE");
        system("CLS");
        system("TITLE YOUR FINISHED!!!");
        cout << "That is the end of the game, more to come!" << endl;
        system)"PAUSE");
        goto beginning;
    }else{
        system("CLS");
        system("TITLE Wrong Answer");
        cout << "Sorry, that is incorrect." << endl;
        system("PAUSE");
        goto beginning;
    }
    return 0;
}


- C++ Programmer
User is offlineProfile CardPM
+Quote Post

Einherjar
RE: Another Game I Need Help With
18 Jul, 2008 - 08:17 PM
Post #2

D.I.C Head
**

Joined: 10 Feb, 2008
Posts: 73


My Contributions
QUOTE(C++ Programmer @ 19 Jul, 2008 - 12:07 AM) *

Please help, it keeps giving me errors when I compile it, it says the error is where it says getline (firstquestion); Please repost it with this problem fixed, thank you in advance,
CODE
#include<iostream>
#include<string>
using namespace std;

int main(void)
{
    beginning:
    system("CLS");
    system("TITLE Play Game or Load Game?");
    string question1;
    string question2;
    string question3;
    string question4;
    string question5;
    string firstquestion;
    double dpassword;
    system("CLS");
    system("TITLE Test Game");
    cout << "Play Game" << endl;
    cout << "Load Game" << endl;
    cout << "Answer: ";
    getline (firstquestion);
    if(playgameorloadgame == Play Game || Play game || play game){
        goto question1;
    }else if(playgameorloadgame == Load Game || Load game || load game){
        goto loadgame;
    }else{
        cout << "That is invalid" << endl;
        system("PAUSE");
        goto beginning;
    }
    loadgame:
    system("CLS");
    system("TITLE Please enter the password");
    cout << "Please enter the password: " << endl;
    cin >> dpassword;
    if(dpassword == password1){
        goto question1;
    }else if(dpassword == password2){
        goto question2
    }else if(dpassword == password3){
        goto question3
    }else if(dpassword == password4){
        goto question4
    }else if(dpassword == password5){
        goto question5
    }else{
        system("CLS");
        system("TITLE Wrong Password");
        cout << "There are only 5 levels.....for now." << endl;
        system("PAUSE");
        goto beginning;
    }
    question1:
    system("CLS");
    system("TITLE Question 1");
    cout << "What does GPU stand for?" << endl;
    getline (question1);
    if(question1 == Graphics Processing Unit || Graphics Processing unit || Graphics processing unit || graphics processing unit){
        system("CLS");
        system("TITLE Correct!");
        cout << "That is correct, here is the password: password1" << endl;
        cout << "That is not a L that is a one." << endl;
        system("PAUSE");
        goto question2;
    }else{
        system("CLS");
        system("TITLE Wrong Answer");
        cout << "Sorry, that is incorrect." << endl;
        system("PAUSE");
        goto beginning;
    }
    question2:
    system("CLS");
    system("TITLE Question 2");
    cout << "What does CPU stand for?" << endl;
    getline (question2);
    if(question2 == Central Processing Unit || Central Processing unit || Central processing unit || central processing unit){
        system("CLS");
        system("TITLE Correct!");
        cout << "That is correct, here is the password: password2" << endl;
        system("PAUSE");
        goto question3;
    }else{
        system("CLS");
        system("TITLE Wrong Answer");
        cout << "Sorry, that is incorrect." << endl;
        system("PAUSE");
        goto beginning;
    }
    question3:
    system("CLS");
    system("TITLE Question 3" << endl;
    cout << "Can your computer run without a graphics card?" << endl;
    getline (question3);
    if(question3 == yes || Yes){
        system("CLS");
        system("TITLE Correct!");
        cout << "That is correct, here is the password: password3" << endl;
        system("CLS");
        goto question4;
    }else{
        system("CLS");
        system("TITLE Wrong Answer");
        cout << "Sorry, that is incorrect." << endl;
        system("PAUSE");
        goto beginning;
    }
    question4:
    system("CLS");
    system("TITLE Question 4");
    cout << "Does a computer need a processor?" << endl;
    getline (question4);
    if(question4 == yes || Yes){
        system("CLS");
        system("TITLE Correct!");
        cout << "That is correct, here is the password: password4" << endl;
        system("PAUSE");
        goto question5;
    }else{
        system("CLS");
        system("TITLE Wrong Answer");
        cout << "Sorry, that is incorrect." << endl;
        system("PAUSE");
        goto beginning;
    }
    question5:
    system("CLS");
    system("TITLE Question 5");
    cout << "Can you use your T.V. as a monitor?" << endl;
    getline (question5);
    if(question5 == yes || Yes){
        system("CLS");
        system("TITLE Correct!");
        cout << "That is correct, here is the password: password5" << endl;
        system("PAUSE");
        system("CLS");
        system("TITLE YOUR FINISHED!!!");
        cout << "That is the end of the game, more to come!" << endl;
        system)"PAUSE");
        goto beginning;
    }else{
        system("CLS");
        system("TITLE Wrong Answer");
        cout << "Sorry, that is incorrect." << endl;
        system("PAUSE");
        goto beginning;
    }
    return 0;
}


- C++ Programmer


getline(cin, firstquestion);

Also, don't use goto's. Use functions or loops or something.
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Another Game I Need Help With
18 Jul, 2008 - 10:12 PM
Post #3

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
wow... I am always surprised that people can get so far without compiling at least once.

You need to look up the use of getline()

Next you need to make sure you define a variable before you try to use it.

Then look at how to compare the values of strings using the == operator.

You really should not use goto... It works, but you will find you code hard to maintain and keep track of. You end up with spaghetti code if you use goto too much. There are control structures (if, switch, while, do-while, for) that do a wonderful job of avoiding the use of goto.
User is offlineProfile CardPM
+Quote Post

C++ Programmer
RE: Another Game I Need Help With
19 Jul, 2008 - 11:43 AM
Post #4

New D.I.C Head
*

Joined: 12 Jun, 2008
Posts: 29


My Contributions
Thank guys, that is going to help, i am still a beginner at it
User is offlineProfile CardPM
+Quote Post

prajayshetty
RE: Another Game I Need Help With
19 Jul, 2008 - 12:04 PM
Post #5

D.I.C Head
Group Icon

Joined: 27 Apr, 2007
Posts: 230


Dream Kudos: 25
My Contributions
CODE

#include <iostream>
#include <string>
using namespace std;
void question1();
void question2();
void question3();
void question4();
void question5();
void main()
{
system("CLS");
    system("TITLE Play Game or Load Game?");
    string question1;
    string question2;
    string question3;
    string question4;
    string question5;
    string firstquestion;
    double dpassword;
    system("CLS");
    system("TITLE Test Game");
    cout << "Play Game" << endl;
    cout << "Load Game" << endl;
    cout << "Answer: ";
    cin.getline (firstquestion);

if(playgameorloadgame == Play Game || Play game || play game){
         qestion1();
    }else if(playgameorloadgame == Load Game || Load game || load game){
         loadgame();
    }else{
        cout << "That is invalid" << endl;
        system("PAUSE");
         main();
}

void loadgame()
{
system("CLS");
    system("TITLE Please enter the password");
    cout << "Please enter the password: " << endl;
    cin >> dpassword;
  
if(dpassword == password1){
        question1();
    }else if(dpassword == password2){
         question2();
    }else if(dpassword == password3){
         question3();
    }else if(dpassword == password4){
         question4();
    }else if(dpassword == password5){
         question5();
    }else{
        system("CLS");
        system("TITLE Wrong Password");
        cout << "There are only 5 levels.....for now." << endl;
        system("PAUSE");
       main();
    }
}
void question1()
{
system("CLS");
    system("TITLE Question 1");
    cout << "What does GPU stand for?" << endl;
    getline (question1);
    if(question1 == Graphics Processing Unit || Graphics Processing unit || Graphics processing unit || graphics processing unit){
        system("CLS");
        system("TITLE Correct!");
        cout << "That is correct, here is the password: password1" << endl;
        cout << "That is not a L that is a one." << endl;
        system("PAUSE");
         question2();
    }else{
        system("CLS");
        system("TITLE Wrong Answer");
        cout << "Sorry, that is incorrect." << endl;
        system("PAUSE");
        main();
    }
}

void question2()
{
system("CLS");
    system("TITLE Question 2");
    cout << "What does CPU stand for?" << endl;
    getline (question2);
    if(question2 == Central Processing Unit || Central Processing unit || Central processing unit || central processing unit){
        system("CLS");
        system("TITLE Correct!");
        cout << "That is correct, here is the password: password2" << endl;
        system("PAUSE");
         question3();
    }else{
        system("CLS");
        system("TITLE Wrong Answer");
        cout << "Sorry, that is incorrect." << endl;
        system("PAUSE");
         main();
    }
}
void question3()
{
system("CLS");
    system("TITLE Question 3" << endl;
    cout << "Can your computer run without a graphics card?" << endl;
    getline (question3);
    if(question3 == yes || Yes){
        system("CLS");
        system("TITLE Correct!");
        cout << "That is correct, here is the password: password3" << endl;
        system("CLS");
        question4();
    }else{
        system("CLS");
        system("TITLE Wrong Answer");
        cout << "Sorry, that is incorrect." << endl;
        system("PAUSE");
         main();
    }
}
void question4()
{
system("CLS");
    system("TITLE Question 4");
    cout << "Does a computer need a processor?" << endl;
    getline (question4);
    if(question4 == yes || Yes){
        system("CLS");
        system("TITLE Correct!");
        cout << "That is correct, here is the password: password4" << endl;
        system("PAUSE");
        question5();
    }else{
        system("CLS");
        system("TITLE Wrong Answer");
        cout << "Sorry, that is incorrect." << endl;
        system("PAUSE");
         main();
    }
}
void question5()
{
system("CLS");
    system("TITLE Question 5");
    cout << "Can you use your T.V. as a monitor?" << endl;
    getline (question5);
    if(question5 == yes || Yes){
        system("CLS");
        system("TITLE Correct!");
        cout << "That is correct, here is the password: password5" << endl;
        system("PAUSE");
        system("CLS");
        system("TITLE YOUR FINISHED!!!");
        cout << "That is the end of the game, more to come!" << endl;
        system)"PAUSE");
        main();
    }else{
        system("CLS");
        system("TITLE Wrong Answer");
        cout << "Sorry, that is incorrect." << endl;
        system("PAUSE");
        main();
    }
}

see the diffrence without goto i hope this run coz idont have a tc compiler and a ide i never compiled it
User is offlineProfile CardPM
+Quote Post

C++ Programmer
RE: Another Game I Need Help With
19 Jul, 2008 - 07:40 PM
Post #6

New D.I.C Head
*

Joined: 12 Jun, 2008
Posts: 29


My Contributions
thanks
User is offlineProfile CardPM
+Quote Post

liverpool0912
RE: Another Game I Need Help With
19 Jul, 2008 - 10:29 PM
Post #7

New D.I.C Head
*

Joined: 4 Jun, 2008
Posts: 36


My Contributions
theres alot errors in this dun wry im working on this 96 errors o0
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 06:12PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month