Input errors in c++ program - c++

when press "1" to start the game a error message comes up first instead of playing the game and then I have to enter "1" 3 times before the game starts and also the quit game option only works when you select "2" first if its not selected first it just comes up as a error message I cant see why it does this can anyone help me please ?
#include "Questions.h"
#include <iostream>
using namespace std;
const int MAXITEMS = 10;
int main ()
{
string question[MAXITEMS] = {"How man cards in a suit",
"How_many_suits_are_there_in_a_standard_pack_of_card",
"How_many_kings_are_in_a_standard_pack_of_cards"};
string answers[MAXITEMS] = {"4", "5", "6"};
int userInput = 0;
int tries = 0;
bool isGameOver = false;
cout << "select 1 to start game" << endl; //gives option to start and quit game
cout << "select 2 to quit game" << endl;
cin >> userInput;
if (userInput == 2)
{
isGameOver = true;
return 0;
};
// when game starts gives option to select question and shows all questions
do
{
if (userInput != 1||2)
{
cout << " Your input is not valid! please try again:" << endl;
// try switch cases for the different outcomes
cout << "select 1 to start game" << endl;
cout << "select 2 to quit game" << endl;
cin >> userInput;
while (!(cin >> userInput))
{
cin.clear(); // clear the error flags
cin.ignore(INT_MAX, '\n'); // discard the row
cout << "Your input is not valid! please try again: ";
cout << "select 1 to start game" << endl;
cout << "select 2 to quit game" << endl;
}
cout << userInput << endl;
}
// reprisent all characters as number to stop while roblem
if(userInput == 1)
{
do
{
cout << "select question" << endl;
for(int i = 0; i != MAXITEMS; i++)
{
cout << i << " " << question[i] << endl;
}
int selectQestion;
cin >> selectQestion;
if(selectQestion == 0||1||2 && tries != 2)
{
cout << "Enter your answer" << endl;
string userAnswer;
cin >> userAnswer;
while (!(cin >> userAnswer))
{
cin.clear(); // clear the error flags
cin.ignore(INT_MAX, '\n');
// discard the row
cout << "Your input is not valid!
please try again: ";
}
if (userAnswer == answers[0])
{
cout << "Correct answer" << endl;
}
else{
cout << "incorrect try again" << endl;
tries++;
cin >> userAnswer;
if (userAnswer == answers[0])
{
cout << "Correct answer" << endl;
}
else
cout << "Incorrect" << endl;
}
}
if (selectQestion == 0 ||1 ||2 && tries == 2)
{
cout << "you can no longer answer this question" << endl;
cout << "try another question" << endl;
}
}
while(userInput == 1);
}
}
while(isGameOver == false);
}
// add stuct or class to handle questions,

if (userInput != 1||2) doesn't do what you think. With the proper paretheses inserted, it is
if ((userInput != 1) || 2)
and 2 is nonzero, hence the condition is always true.
You want
if (userInput != 1 && userInput != 2)

The problem lies here:
if (UserInput!=1||2)
In this line, there are two conditions:
UserInput!=1 , 2
Here , whether user input is 1/2, the second condition 2 is always evaluated as true, which runs the if block
So change it to
if (UserInput!=1 && UserInput!=2)

Related

How to make DUPLICATED ANSWERS wrong?

i am making a word guessing game in c++ (im new at programming btw) im just gonna ask how can i make the "already-answered" answers as wrong and cant get points from the same word again? here's my current code...
#include <iostream>
#include <string>
using namespace std;
int main()
{
int firstQPoint, secondQPoint, thirdQPoint, mane;
char yourChoice, levelChoice, goBack;
string yourFirstAnswer, yourSecondAnswer, yourThirdAnswer;
gameMenu:
cout << "\t GUESS THE WORD GAME";
cout << "\t\n\n MADE BY GROUP FIVE";
cout << "\t\t\n\n 1. PLAY | ENTER \"1\" TO PLAY ";
cout << "\t\t\n\n 2. QUIT | ENTER \"2\" TO QUIT ";
cout << "\t\t\n\n 3. RULES | ENTER \"3\" TO SEE THE RULES";
cout << "\t\t\n\n What Do You Want To Do : ";
cin >> yourChoice;
if (yourChoice == '1') {
cout << "\t GUESS THE WORD GAME";
cout << "\t\n\n MADE BY GROUP FIVE";
selectALevel:
cout << "\t\n\n OKAY, CHOOSE A LEVEL (1-3) : ";
cin >> levelChoice;
switch (levelChoice) {
case ('1'):
cout << "\t GUESS THE WORD GAME";
cout << "\t\n\n MADE BY GROUP FIVE";
cout << "\t\t\n\nGIVE 3 BODY PARTS THAT STARTS WITH LETTER \"T\"";
cout << "1 : ";
cin >> yourFirstAnswer;
if (yourFirstAnswer == "TOE", "TONGUE", "TOOTH") {
cout << "\n\n\t\tNICE, YOU GOT A POINT!";
firstQPoint = 1 + 0;
}
cout << "2 : ";
cin >> yourSecondAnswer;
if (yourSecondAnswer == "TOE", "TONGUE", "TOOTH") {
cout << "\n\n\t\tNICE, YOU GOT A POINT!";
secondQPoint = 1 + firstQPoint;
}
cout << "3 : ";
cin >> yourThirdAnswer;
if (yourThirdAnswer == "TOE", "TONGUE", "TOOTH") {
cout << "\n\n\t\tNICE, YOU GOT A POINT!";
thirdQPoint = 1 + secondQPoint;
}
break;
case ('2'):
break;
case ('3'):
break;
default:
goto selectALevel;
}
}
else if (yourChoice == '3') {
do {
cout << "\t GUESS THE WORD RULES";
cout << "\t\t\n\n1. ONLY USE UPPERCASE LETTERS";
cout << "\t\t\n\n1. ONLY USE SINGULAR WORDS";
cout << "\t\t\n\n ENTER \"1\" TO GO BACK : ";
cin >> goBack;
if (goBack == '1') {
goto gameMenu;
}
} while (goBack != '1');
}
else if (yourChoice == '2') {
cout << "\t\t\n\n Okay, Goodbye!";
}
return 0;
}
i tried the longer way, where i will manually code it like this
#include <iostream>
using namespace std;
int main()
{
int number, again;
cout << "give 2 number";
cin >> number;
cout << "again :";
cin >> again;
if (number == 1 && again == 2) {
cout << "correct";
else if (number == 2 && again == 1)
{
cout << "correct";
}
}
}
but it's very hard since im working with too many combinations! thanks in advance for answering!
Inside each switch case you can make a loop to repeat the question if the word is wrong.
At the beginning of the switch (before the loop) you can create an empty list where you will store every answer they give.
In the end you only need to make a function that goes through that same list and checks if a word is inside it or not.

Still being prompted after entering a valid input value

I made this for an assignment but even if I enter a valid input from the desired range I still get prompted. This is happening to both input prompts. I suspect the problem is in the while blocks of the setupGame function.
#include <iostream>
using namespace std;
bool setupGame(int numberRef, int triesRef);
int main(){
cout<<"hello world";
setupGame(4,4);
cout<<"enough";
}
//SETUP GAME FUNCTION
bool setupGame(int numberRef, int triesRef) {
do {
cout << "ENTER A NUMBER BETWEEN 1 and 100" << endl;
cin >> numberRef;
cin.clear();
//your code here
cout << "You entered: " << numberRef << endl;
if (numberRef==-1) {
cout << "You do not want to set a number " << endl;
cout << "so you stopped the program" << endl;
}
else if(numberRef >=1 && numberRef <=100)
do {
cout << "ENTER TRIES BETWEEN 3 and 7" << endl;
cin >> triesRef;
cin.clear();
//cin.ignore( '\n');
cout<< "You entered: "<< triesRef<< endl;
if (triesRef==-1) {
cout << "You do not want to set tries. ";
cout << "so you stopped the program" << endl;
} else if(triesRef <= 3 && triesRef >= 7){
cout<<"Number of tries should be between 3 and 7";
}
}
while(numberRef >=1 && numberRef <=100);{
return true;
}
}
while(triesRef >= 3 && triesRef <= 7);{
return true;
} }
You're tangling yourself up with these nested loops. Your prompt keeps printing because the while loop:
while(numberRef >=1 && numberRef <=100)
is going to keep repeating it's preceding do block until you enter a value less than 1 or greater than 100, same goes for the last while loop as well.
I assume you're using cin.clear() to flush the previous input, if you are then stop it, that is not the purpose of cin.clear(). It's instead use to clear the error state of cin. Please thoroughly read up on it here.
Below is the code to achieve what you want, please observe how I implemented the while loops after each cin prompt to ensure that a valid character is entered.
#include <iostream>
#include <fstream>
using namespace std;
bool setupGame(int numberRef, int triesRef);
int main(){
cout<<"hello world";
setupGame(4,4);
cout<<"enough";
}
//SETUP GAME FUNCTION
bool setupGame(int numberRef, int triesRef) {
cout << "ENTER A NUMBER BETWEEN 1 and 100" << endl;
cin >> numberRef;
while((numberRef < 1 || numberRef > 100 || cin.fail()) && numberRef != -1) {
cin.clear(); // Used to clear error state of cin
cin.ignore(); // Might want to ignore the whole line
cout<<"Number should be between 1 and 100, or -1 , please try again: ";
cin>>numberRef;
}
cout << "You entered: " << numberRef << endl;
if (numberRef==-1) {
cout << "You do not want to set a number " << endl;
cout << "so you stopped the program" << endl;
}
if(numberRef >=1 && numberRef <=100) {
cout << "ENTER TRIES BETWEEN 3 and 7" << endl;
cin >> triesRef;
while(triesRef < 3 || triesRef > 7 || cin.fail()) {
cin.clear(); // Used to clear error state of cin
cin.ignore(); // Might want to ignore the whole line
cout<<"Tries should be between 3 and 7 , please try again: ";
cin>>triesRef;
}
cout<< "You entered: "<< triesRef<< endl;
if (triesRef==-1) {
cout << "You do not want to set tries. ";
cout << "so you stopped the program" << endl;
return false;
}
}
}

using getline() to input strings into the program is causing some kind of overflow into the next input [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am having a number of problems in my program that all have to do with input.
The first thing in the program I ask the user to input is their name which I do so with this
cout << "Please tell me your name." << endl;
getline(cin, user_name);
cout << "Hello " << user_name << " and welcome to Fantasy Battle!" << endl;
where user_name is declared as a string variable elsewhere. This part seems to have no problems as the following message displays to the screen correctly
The next input from the user comes from this code
{
cout << "Hello, what would you like to do?" << endl;
cout << "1. Play" << endl << "2. Exit" << endl;
cout << "Please enter the number corresponding to your choice from the list
above." << endl;
for(;;)
{
if(cin >> menuChoice)
{
if(cin.get() == '.')
{
cin.clear();
cin.ignore(10000, '\n');
}
if(menuChoice == 1 || menuChoice == 2)
break;
else
{
cout << "You did not enter a valid menu option. Please try
again." << endl;
cin.clear();
cin.ignore(100000, '\n');
}
}
else
{
cout << "You did not enter a valid menu option. Please try again."
<< endl;
cin.clear();
cin.ignore(100000, '\n');
}
}
if(menuChoice == 2)
{
return 2;
}
else
{
//setup a fight code further down
}
One the first run through if I enter 2 it will exit the program successfully from main or if enter 1 it will run through the fight function. However, if I go through 1 fight and get back the program asking me to either enter 1 or 2 to play or exit, I can enter 2 infinite times and it will not exit the program. I am not sure what it causing this.
for(;;)
{
game = menu();
if(game == 2)
{
break;
}
else
{
fight();
}
}
return 0;
The code inside the menu() function of my program is as follows and is where the rest of the input for my program is contained. I am using getline(cin, fighterName) to get a string from the user to use as a name for each character they want to create
The problem I am having is that it starts to just save the name of characters as empty without asking.
cout << "How many fighters should be on Team 1?" << endl;
//Input Validation
for(;;)
{
if(cin.get() == '.')
{
cin.clear();
cin.ignore(100000, '\n');
}
if(cin >> team1Size)
{
if(team1Size <= 0)
{
cout << "The team must be a size of at least 1 fighter. Please try again." << endl;
cin.clear();
cin.ignore(100000, '\n');
}
else
{
break;
}
}
else
{
cout << "You did not enter a valid number. Please try again." << endl;
cin.clear();
cin.ignore(100000, '\n');
}
}
cout << "How many fighters should be on Team 2?" << endl;
//Input Validation
for(;;)
{
if(cin.get() == '.')
{
cin.clear();
cin.ignore(100000, '\n');
}
if(cin >> team2Size)
{
if(team2Size <= 0)
{
cout << "The team must be a size of at least 1 fighter. Please try again." << endl;
cin.clear();
cin.ignore(100000, '\n');
}
else
{
break;
}
}
else
{
cout << "You did not enter a valid number. Please try again." << endl;
cin.clear();
cin.ignore(100000, '\n');
}
}
//Set up team 1
cout << "Begin setup for team 1:" << endl << endl;
for(int i = 0; i < team1Size; i++)
{
cout << "Which character type should fighter " << i+1 << " be?" << endl;
cout << "1. Barbarian" << endl;
cout << "2. BlueMen" << endl;
cout << "3. Vampire" << endl;
cout << "4. Medusa" << endl;
cout << "5. Harry Potter" << endl;
cout << "Please enter the number corresponding to your choice from the list above." << endl;
for(;;)
{
if(cin.get() == '.')
{
cin.clear();
cin.ignore(100000, '\n');
}
if(cin >> fighterType)
{
if(fighterType < 1 || fighterType > 5)
{
cout << "You did not enter a valid choice. Please try again." << endl;
cin.clear();
cin.ignore(100000, '\n');
}
else
break;
}
else
{
cout << "You did not enter a valid choice. Please try again." << endl;
cin.clear();
cin.ignore(100000, '\n');
}
}
//Now that we have the desired type of the fighter we must add a fighter of the correct type to the linked list
//representing team 1. We will do so by calling the add function of the linked list
cout << "Please enter the name of this fighter." << endl;
getline(cin, fighterName);
if(fighterType == 1)
{
team1.addBack("Barbarian", fighterName);
}
else if(fighterType == 2)
{
team1.addBack("BlueMen", fighterName);
}
else if(fighterType == 3)
{
team1.addBack("Vampire", fighterName);
}
else if(fighterType == 4)
{
team1.addBack("Medusa", fighterName);
}
else
{
team1.addBack("HarryPotter", fighterName);
}
}
cout << "Team 1 has been created!" << endl << endl;
//Set up team 2
cout << "Begin setup for team 2:" << endl << endl;
for(int i = 0; i < team2Size; i++)
{
cout << "Which character type should fighter " << i+1 << " be?" << endl;
cout << "1. Barbarian" << endl;
cout << "2. BlueMen" << endl;
cout << "3. Vampire" << endl;
cout << "4. Medusa" << endl;
cout << "5. Harry Potter" << endl;
cout << "Please enter the number corresponding to your choice from the list above." << endl;
for(;;)
{
if(cin.get() == '.')
{
cin.clear();
cin.ignore(100000, '\n');
}
if(cin >> fighterType)
{
if(fighterType < 1 || fighterType > 5)
{
cout << "You did not enter a valid choice. Please try again." << endl;
cin.clear();
cin.ignore(100000, '\n');
}
else
break;
}
else
{
cout << "You did not enter a valid choice. Please try again." << endl;
cin.clear();
cin.ignore(100000, '\n');
}
}
//Now that we have the desired type of the fighter we must add a fighter of the correct type to the linked list
//representing team 2. We will do so by calling the add function of the linked list
cout << "Please enter the name of this fighter." << endl;
getline(cin, fighterName);
if(fighterType == 1)
{
team2.addBack("Barbarian", fighterName);
}
else if(fighterType == 2)
{
team2.addBack("BlueMen", fighterName);
}
else if(fighterType == 3)
{
team2.addBack("Vampire", fighterName);
}
else if(fighterType == 4)
{
team2.addBack("Medusa", fighterName);
}
else
{
team2.addBack("HarryPotter", fighterName);
}
}
cout << "Team 2 has been created!" << endl << endl;
cout << "Let the fight begin!" << endl << endl;
return 0;
}
The final piece of input from my code is the following which simply asks the user to enter a character either y or n and then executes a function if y is entered.
cout << "Would you like to see the contents of the loserPile?" << endl;
cout << "Please enter y for yes or n for no" << endl;
for(;;)
{
if(cin >> displayLosers)
{
if(displayLosers != 'y' && displayLosers != 'n')
{
cout << "You did not enter either y or n. Please try again." << endl;
cin.clear();
cin.ignore(100000, '\n');
}
else
break;
}
else
{
cout << "You did not enter either y or n. Please try again." << endl;
cin.clear();
cin.ignore(100000, '\n');
}
}
if(displayLosers == 'y')
{
losers.displayPile();
}
If someone could point out where I am making the error in obtaining user input I would appreciate it as I am running out of things to try that I know of.
You are creating a lot of problems by adding if(cin.get() == '.')
The >> operator will convert the input string "1." to 1, and if you call ignore(...,'\n') the . and any other characters before \n will be ignored. Test for if(cin >> number){...} is also not necessary. You can initialize the value to -1 to indicate an error:
int menuChoice;
for(;;)
{
menuChoice = -1;
cin >> menuChoice;
cout << menuChoice;
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
if(menuChoice == 1 || menuChoice == 2)
{
cout << menuChoice << "\n";
break;
}
cout << "You did not enter a valid menu option. Please try again." << endl;
}
Just make sure you are using the right input. For Yes or No option the input should be char:
cout << "enter y or n\n";
for(;;)
{
char val;
cin >> val;
if(val != 'y' && val != 'n')
{
cout << "You did not enter either y or n. Please try again." << endl;
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
else
break;
}

Input parsing problems

When a user enters spaces in between digits to create a reference string it throws everything off and will even carry numbers over to the next cin. If however they have letters in between and no spaces it works fine. The assignment was for a page replacement sim.
Code (this is only the part of the code that should effect my problem):
void main()
{
bool again = false;
bool reuse = false;
bool valid;
int use;
int refLength;
vector<int> ref(0);
vector<frame> frames(0);
string refString;
string user;
//ask how long the user wants the ref string to be
do{
valid = false;
while (!valid&&!reuse)//take choice of ref string
{
cout << "How long do you wish the reference string to be? ";
if (!(cin >> refLength))
{
cin.clear();//.clear and .ignore keep cin from errors and forced infinite loop repeating following cout
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "The length must be enter as an integer value between ";
valid = false;
}
else
{
cout << "You have chosen to have a Ref string of " << refLength << " length " << endl;
valid = true;
}
}
valid = false;
while (!valid&&!reuse)
{
cout << "Do you want to enter a ref string or randomly generate one" << endl;
cout << "of your chosen length? Enter 1 to generate and 2 to input the string ";
if (!(cin >> use) | (use<0 || use>2))
{
cin.clear();//.clear and .ignore keep cin from errors and forced infinite loop repeating following cout
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "You must enter an integer between 1 and 2";
}
else
{
valid = true;
if (use == 1)
{
make(ref, refLength);
}
else
{
cout << "please enter a ref string of chosen length entering" << endl;
cout << "fewer digits will cause 0's to be added. Entering more" << endl;
cout << "will cause those past the chosen length to be dropped " << endl;
cout << "any letters will be ignored but spaces throw things off" << endl;
cout << "Also all entries must be single digit integers (0-9) " << endl;
cin >> refString;
make(ref, refLength, refString);
}
use = 0;
}
}
cout << endl;
/*for(int i=0;i<ref.size();i++)
{
cout<<ref[i]<<" ";
}*/
valid = false;
while (!valid)
{
cin.clear();
//errors ********************************************88
cout << "How many frames do you want (1-7) ";
if (!(cin >> use) | (use<0 || use>7))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "You must enter an integer between 1 and 7 ";
valid = false;
}
else
{
valid = true;
setUpFrames(use, frames);
use = 0;
}
}
valid = false;
while (!valid)
{
cout << "Enter 1 for FIFO or 2 for LRU pageRep algo or 3 for Optimal";
if (!(cin >> use) | (use<0 || use>3))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Must be int between 1 and 3";
}
else if (use == 1)
{
cout << endl << "# of Page Faults ";
cout << FIFO(ref, frames);
valid = true;
}
else if (use == 2)
{
cout << endl << "# of Page Faults ";
cout << LRU(ref, frames);
valid = true;
}
else
{
cout << endl << "# of Page Faults ";
cout << Optimal(ref, frames);
valid = true;
}
}
cout << endl;
cout << "do you want to try again ? Enter y for yes anything else for no" << endl;
cin >> user;
if (user == "y")
{
again = true;
cout << "do you want to use the same reference string? y for yes anything else for no" << endl;
cin >> user;
if (user == "y")
{
reuse = true;
}
else
{
reuse = false;
}
}
else
{
again = false;
}
} while (again);
}
If you want cin/cout interaction word/line by word/line use getline, otherwise confusion will arise.

C++ exit loop not working

well its a simple project it does everything as it should minus it wont exit when it is suppose to.
I have tried many different ways including goto statements I tried a if loop but got nothing but errors. The current code gives no errors just I dont know where to go to make it exit. It doesnt have to be fancy this is only my second program
// C// Guess My Number
// The classic number guessing game
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(static_cast<unsigned int>(time(0))); //seed random number generator
int secretNumberE = rand() % 10 + 1;
int secretNumberM = rand() % 100 + 1;// random number between 1 and 100
int secretNumberH = rand() % 1000 + 1;
int tries = 0;
int guess;
char play;
{
cout << "\tWelcome to Guess My Number\n\n";
START:
cout << "Difficulty Levels\n\n";
cout << "1 - Easy\n";
cout << "2 - Normal\n";
cout << "3 - Hard\n\n";
int choice;
cout << "Choice: ";
cin >> choice;
switch (choice)
{
case 1:
cout << "You picked Easy.\n";
do
{
cout << "Enter a guess 1-10: ";
cin >> guess;
++tries;
if (guess > secretNumberE)
{
cout << "Too high!\n\n";
}
else if (guess < secretNumberE)
{
cout << "Too low!\n\n";
}
else
{
cout << "\nThat's it! You got it in " << tries << " guesses!\n";
}
} while (guess != secretNumberE);
std::cout << "Do you want to play again y/n? ";
cin >> play;
if ( play = 'y' ){
goto START;
}
else if (play = 'n')
{
cout << " Thank you for playing. ";
return 0;
}
break;
case 2:
cout << "You picked Normal.\n";
do
{
cout << "Enter a guess 1-100: ";
cin >> guess;
++tries;
if (guess > secretNumberM)
{
cout << "Too high!\n\n";
}
else if (guess < secretNumberM)
{
cout << "Too low!\n\n";
}
else
{
cout << "\nThat's it! You got it in " << tries << " guesses!\n";
}
} while (guess != secretNumberM);
std::cout << "Do you want to play again y/n? ";
cin >> play;
if ( play = 'y' ){
goto START;
}
else if (play = 'n')
{
cout << " Thank you for playing. ";
return 0;
}
break;
case 3:
cout << "You picked Hard.\n";
do
{
cout << "Enter a guess 1-10: ";
cin >> guess;
++tries;
if (guess > secretNumberH)
{
cout << "Too high!\n\n";
}
else if (guess < secretNumberH)
{
cout << "Too low!\n\n";
}
else
{
cout << "\nThat's it! You got it in " << tries << " guesses!\n";
}
} while (guess != secretNumberH);
std::cout << "Do you want to play again y/n? ";
cin >> play;
if ( play = 'y' ){
goto START;
}
else if (play = 'n')
{
cout << " Thank you for playing. ";
return 0;
}
break;
default:
cout << "You made an illegal choice.\n";
goto START;
return 0;
}}}
if ( play = 'y' ){
goto START;
}
else if (play = 'n')
{
cout << " Thank you for playing. ";
return 0;
}
The first if will always be true, because you are using the assignment operator rather than the equality operator. You need to use == to compare two values.
...
char play;
{
...
There seems to be an extra { in your code that you are wrapping your stuff with.
Things that are clear to me that you need to work on, indentation. There is probably an auto-format shortcut in your IDE. Start using that. It's impossible to read your code well this will lead to a bunch of errors in the long run for simple things that you will be banging your head over.
goto highly recommend not using this unless you know what your doing.
Start learning functions/methods they will save your life and overall improve you workflow.
and you can replace goto with it.
example of a function..
int startGame(){
cout << "Difficulty Levels\n\n";
cout << "1 - Easy\n";
cout << "2 - Normal\n";
cout << "3 - Hard\n\n";
int choice = 0;
cout << "Choice: ";
cin >> choice;
return choice;
}
Other things.
if ( play = 'y' ) needs to be if ( play == 'y' ) rinse repeat this because you are trying to check for equality(conditional) not setting a value which is what one = does.
Also, ALWAYS INITIALIZE VALUES int choice; should be int choice = 0; or some default value.
use the "break" keywork
do
{
if(mycondition)
{
break;
}
} while (loopCondition);