Need Help Scrambling Words for a Game.
Hello! I am trying to make a unscrambling game. I need to know how to scramble words that I read from a file? Also how would I loop the same word back the prompt if I unscramble the word wrong?
Code:
#include <iostream>
using namespace std;
#include <fstream>
#include <cstring>
#include <cstdlib>
int main()
{
ifstream list;
char word[15], name[15], choice, answer[15];
list.open ("list.txt");
do
{
list >> name;
cout << "Unscramble the following word: " <<name << endl;
cout << "Write your answer: ";
cin >> answer;
while(strcmp(answer, name) == 0)
{
cout << "Great!\n";
break;
}
while(!strcmp(answer,name) == 0)
{
cout <<"Try again.\n";
break;
}
if(strcmp(answer,name) == 0)
{
cout << "Do you want to play again [y/n] ";
cin >> choice;
if(choice == 'n' || choice == 'N')
{
cout <<"Bye!\n";
break;
}
}
}while (!list.eof());
return 0;
}