soknaly

Word Jumble C++

Feb 9th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.90 KB | None | 0 0
  1. ///Word Jumble by Sokna Ly  
  2. #include <stdlib.h>
  3. #include <iostream>
  4. #include <conio.h>
  5. const int NUM=10;
  6. const int SIZE=100;
  7. void main(){
  8.     char *words[NUM][SIZE]={{"hello","used as a greeting when you see or meet someone."},
  9.                              {"better","comparitive of good."},
  10.                            {"password","a secret group of letters or numbers that you must type into a computer before you can use a system or program."},
  11.                            {"guest","someone who is invited to an event or special occasion."},
  12.                            {"persuade","to make someone decide to do something, especially by giving them reasons why they should do it."},
  13.                            {"anniversary","a date on which something special or important happened in a previous year."},
  14.                            {"computer","an electronic machine that stores information and uses programs to help you."},
  15.                            {"economy","the system by which a country's money and goods are produced and used."},
  16.                            {"disable","to make someone unable to use a part of their body properly."},
  17.                            {"vulnerable","someone who is vulnerable can be easily harmed or hurt."}
  18.                              };
  19.    LOOP:
  20.    clrscr();
  21.    cout<<"\t\tWelcome to Word Jumple!!!(Dev::Sokna Ly)\n\n\n"<<endl;
  22.    //choose one word randomly
  23.    randomize();
  24.     int choice=rand()%9;
  25.    char chosenWord[20];
  26.     char hint[100];
  27.     strcpy(chosenWord,words[choice][0]);
  28.    strcpy(hint,words[choice][1]);
  29.    char jumble[20];
  30.     strcpy(jumble,chosenWord);
  31.    for(unsigned int i=0;i<strlen(jumble);++i){
  32.     int index1=rand()%strlen(jumble);
  33.       int index2=rand()%strlen(jumble);
  34.       char tmp=jumble[index1];
  35.       jumble[index1]=jumble[index2];
  36.       jumble[index2]=tmp;
  37.    }
  38.    cout << "Unscramble the letters to make a word.\n";
  39.     cout << "Enter 'hint' for a hint.\n";
  40.    cout <<"Enter 'answer' for an answer.\n";
  41.     cout << "Enter 'quit' to quit the game.\n\n";
  42.     cout << "The jumble is: "<<jumble<<endl;
  43.    AGAIN:
  44.    cout<<"What is your answer???: ";
  45.    char answer[15];
  46.    cin>>answer;
  47.    while(strcmp(answer,"quit")!=0){
  48.     if(strcmp(answer,chosenWord)==0){
  49.         cout<<"Awesome! You're correct."<<endl;
  50.          char choose;
  51.         cout<<"Do you want to play again???('y'/'n'): ";
  52.         cin>>choose;
  53.          if(choose=='y' || choose=='Y')
  54.             goto LOOP;
  55.         else
  56.                 exit(0);
  57.  
  58.     }else if(strcmpi(answer,"hint")==0){
  59.         cout<<"***HINT: "<<hint<<endl;
  60.          goto AGAIN;
  61.     }else if(strcmpi(answer,"answer")==0){
  62.         cout<<"The Answer is: "<<chosenWord<<endl;
  63.          char choose;
  64.         cout<<"Do you want to play again???('y'/'n'): ";
  65.         cin>>choose;
  66.         if(choose=='y' || choose=='Y')
  67.             goto LOOP;
  68.         else
  69.             exit(0);
  70.       }else{
  71.         cout<<"Incorrect!"<<endl<<"Please try again!!!"<<endl;
  72.          goto AGAIN;
  73.     }
  74.    }
  75.    exit(0);
  76.    getch();
  77. }
Advertisement
Add Comment
Please, Sign In to add comment