I just started messing around with C++ but I am stuck. Any help would be much appreciated.
I want to change the value of gameState from true
to false
by passing in another function, however, my thought process seems to be incorrect:
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
void changeState(bool gameState){
string answer;
cout << "End game? Y/N" << endl;
cin >> answer;
if(answer == "Y"){
gameState = false;
} else if (answer == "N"){
gameState = true;
}
}
void gameLoop(){
bool gameState = true;
while(gameState == true){
cout << "Game is being played" << endl;
changeState(gameState);
}
}
int main(){
gameLoop();
return 0;
}