Jump to content

Not about Ragnarok but C++ help me pls


Nero

Recommended Posts


  • Group:  Members
  • Topic Count:  74
  • Topics Per Day:  0.02
  • Content Count:  194
  • Reputation:   2
  • Joined:  12/18/11
  • Last Seen:  

#include<iostream.h>
#include<conio.h>

main()
{
clrscr();
int a,b,c,d;
cout<<"Welcome To Word Fruit Hunt!\n";
cout<<"Please Choose you Game Mode ";
cout<<"Just Type\n 1 for Easy\n 2 for Medium\n 3 for Hard\n";
cout<<"Type Here: ";
cin>>a;
{
if(a==1)
cout<<"A X O B\nP Z ? C\n? D A N\nL O N D\nE Q G O\nI W ? T\n";
else if (a==2)
cout<<" P I N E T L\n D A N G E R\n M A P M O R\n S C O A D E\n Q N R Z Y P\n A U S T I A\n";
else if (a==3)
cout<<"A B E M G J L S D\nG R A P E S K P R\nC D F I H L Q N O\nU Z O L E M O P F\nX W B Z Y V U N T";
}
getch();
return 0;
}
 

 

Im really beginner to C++ 

but i know some of you is Expert so i really need your help

 

The answer is Fixed..

 

this project is C++ game projet.

 

 

I need that if you type the answer in game mode 1 example the 1st answer is Apple or Orange

it will cout your correct else Wrong..

 

in game mode 2 the same but the fixed answer is papaya and lemon.

 

in game mode 3 the fixed answer is pomelo grapes and melon

 

 

Thank you in advance..

Hoping for fast reply..

 

 

 

Link to comment

  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  249
  • Reputation:   72
  • Joined:  10/20/12
  • Last Seen:  

Hi, you can do something like this:

 

string answer;
//...
cin >> answer;
if( a==1 && (answer.compare("APPLE") == 0 || answer.compare("ORANGE") == 0) )
    cout << "Right!";
else
    cout << "Wrong!";

Notice, that the compare-function works casesensitive, so you need to upper every char in "answer" or find a comparenocase function.

 

By the way you can use switch for integer values:

 

switch(a) {
  case 1:
    cout << "A X O B\nP Z ? C\n? D A N\nL O N D\nE Q G O\nI W ? T\n";
    break;
  case 2:
     cout << " P I N E T L\n D A N G E R\n M A P M O R\n S C O A D E\n Q N R Z Y P\n A U S T I A\n";
     break;
  case 3:
     cout << "A B E M G J L S D\nG R A P E S K P R\nC D F I H L Q N O\nU Z O L E M O P F\nX W B Z Y V U N T";
     break;
}

Just looks better :D

Edited by Jey
Link to comment

  • Group:  Members
  • Topic Count:  74
  • Topics Per Day:  0.02
  • Content Count:  194
  • Reputation:   2
  • Joined:  12/18/11
  • Last Seen:  

Thank you for your reply. but im having error when i used it can you help me to have the full code? im really sorry im just a beginner..

Link to comment

  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  249
  • Reputation:   72
  • Joined:  10/20/12
  • Last Seen:  

Sure!

I tested it with something like the following (Only the easy one works, but I think you can easily add the other two). I hope this will help you ^^

#include <iostream>

using namespace std;

int main()
{
    int a,b,c,d;
    string answer;
    bool isCorrect=false;
    cout << "Welcome To Word Fruit Hunt!\n";
    cout << "Please Choose you Game Mode ";
    cout<< "Just Type\n 1 for Easy\n 2 for Medium\n 3 for Hard\n";
    cout << "Type Here: ";
    cin >> a;
    switch(a) {
        case 1: //Easy
            cout << "A X O B\nP Z ? C\n? D A N\nL O N D\nE Q G O\nI W ? T\n";
            break;
        case 2: //Medium
            cout << " P I N E T L\n D A N G E R\n M A P M O R\n S C O A D E\n Q N R Z Y P\n A U S T I A\n";
            break;
        case 3: //Hard
            cout << "A B E M G J L S D\nG R A P E S K P R\nC D F I H L Q N O\nU Z O L E M O P F\nX W B Z Y V U N T";
            break;
        default:
            return -1;
    }
    //User Input (answer)
    cin >> answer;
    switch(a) {
        case 1: //Easy
            if( answer.compare("APPLE") == 0 || answer.compare("ORANGE") == 0 )
                isCorrect = true;
            break;
        case 2:
            //TODO Medium string comparison
            break;
        //TODO Hard case
    
    }
    if( isCorrect )
        cout << "Right!";
    else
        cout << "Wrong!";
    return 0;
}
Edited by Jey
  • Upvote 1
Link to comment

  • Group:  Members
  • Topic Count:  74
  • Topics Per Day:  0.02
  • Content Count:  194
  • Reputation:   2
  • Joined:  12/18/11
  • Last Seen:  

i've tried the program but it seems that when im going to enter the answer the program will terminate

Link to comment

  • Group:  Members
  • Topic Count:  74
  • Topics Per Day:  0.02
  • Content Count:  194
  • Reputation:   2
  • Joined:  12/18/11
  • Last Seen:  

im using dev c++ 5.0.0.4

Link to comment

  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  249
  • Reputation:   72
  • Joined:  10/20/12
  • Last Seen:  

Did you select the hard game mode? If yes, there is no case in the secound switch (TODO comment). Try to select easy.

Edited by Jey
Link to comment

  • Group:  Members
  • Topic Count:  74
  • Topics Per Day:  0.02
  • Content Count:  194
  • Reputation:   2
  • Joined:  12/18/11
  • Last Seen:  

oops im sorry my mistake it will display the Right but in milisecond only... how to display the Right or Wrong in long period of time .. thank you very much for helping me,

Edited by sampang99
Link to comment

  • Group:  Members
  • Topic Count:  74
  • Topics Per Day:  0.02
  • Content Count:  194
  • Reputation:   2
  • Joined:  12/18/11
  • Last Seen:  

I alread solved it THANK YOU VERY MUCH Sir Jey God bless to you and your family! :D

Link to comment

  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  249
  • Reputation:   72
  • Joined:  10/20/12
  • Last Seen:  

You're welcome :D

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...