I've been trying for 2 days but I can't think of an answer. If you can spot the problems in my code, i'd appreciate it loads. I'm trying to a code that tells you to unscramble words, starting from a 3 letter word to a 12 letter word.
I tried doing this using Dev c++. Lines 44-105 cause infinite looping. I can see why but I can't seem to get a solution to repeat the menu selection 1-3. And lines 102-105 are a pain in the butt. It appears every single time after a y or n. Lines 77-84. Even lines 85-94 don't give out the right output.
The problem with my code is that it doesn't add up the scores. Can you teach me how to do that? I need to do it without a global variable. Declaring it in main() and passing it on to the other functions as parameters.
Another question. How can i output a picture? That's supposed to be my output when the user enters the number 2. How do i create another window to display the object?
Functions SecondWord to TenthWord are about the same.
This is my code:
I can only help you out with the logic in the program because I am not familiar with dev c++ and I'm just a fledgling programmer. hopefully this helps you along a bit though:
after line 43, instead of creating a loop that goes through the choices try this one. if the choice is not 1,2, or 3 it displays an error message and asks the user to enter their choice again. this should fix lines 102-105 by error trapping the input from the user before you go through the choices.
while(choice!=1&&choice!=2&&choice!=3)
{
cout << "Please enter numbers 1 - 3 only! << endl << endl << endl;
cout<<"Please Choose The Following Options:"<<endl;
cout<<"1.Play Scrabble."<<endl;
cout<<"2.Developers Picture."<<endl;
cout<<"3.Quit."<<endl<<endl<<endl;
cin>>choice;
}
now that you know you have a choice that is 1 to 3 create a loop for choices 1 and 2(if the user entered 3 it will skip the loop and go straight to the end of the program.) it should be something like this:
while(choice == 1 || choice == 2)
{
if (choice == 1)
{
do //created a nested post-test loop to ask the user if the want to play the game again
{
char again = ''; //creates the variable char inside the loop to make it more efficient. this is the only place you //need it.
cout << //scrabble game code goes here.
//prompt the user to play again inside the loop
cout << "Would you like to play again?" << endl;
cin >> again
}while(again == 'Y' || again == 'y')
if(choice == 2)
{
//display developer picture code
}
//now display the menu and prompt the user for a decision
cout << "What would you like to do?" << endl << endl;
cout<<"Please Choose The Following Options:"<<endl;
cout<<"1.Play Scrabble."<<endl;
cout<<"2.Developers Picture."<<endl;
cout<<"3.Quit."<<endl;
cin >> choice;
cout<<endl<<endl;
//error trap the user's choice again by using the same loop as before
while(choice!=1&&choice!=2&&choice!=3)
{
cout << "Please enter numbers 1 - 3 only! << endl << endl << endl;
cout<<"Please Choose The Following Options:"<<endl;
cout<<"1.Play Scrabble."<<endl;
cout<<"2.Developers Picture."<<endl;
cout<<"3.Quit."<<endl;
cin >> choice;
cout<<endl<<endl;
}
}//end of while loop for choices
system("PAUSE");
return EXIT_SUCCESS;
}//end of main function
hope that helps a bit.
idk about outputting a picture or adding your marks up though. good luck. post the solution if you get it solved :)
My first point is to put the code inside the braces after if(choice==1) into a function which is called straight after if(choice==1). Actually you would be better to use a switch statement instead of those if statements.
1 2 3 4 5 6 7
switch (choice)
case 1:
PlayScrabble();
case 2:
DevelopPicture();
case 3:
exit(0);
Now declare the functions before main() and put their implementation after main().
Functions SecondWord to TenthWord are about the same.
If the functions are the same, why not have one function called ProcessWord? You might need to put your 10 words into an array.
You really do want avoid writing the same code 10 times over.