I have this code:
#include <iostream>
#include <vector>
#include <ctime>
#include <math.h>
#include <string>
using namespace std;
int main()
{
srand(time(0));
string command_one;
int slot;
cout<<"One chip or Quit?\n";
getline(cin, command_one);
if(command_one=="One chip"){
cout<<"Pick a slot between 0 and 8 (inclusive)\n";
cin>>slot;
if(slot>=0 and slot<=8){
double position=slot;
}
else{
cout<<"This Option is invalid!\n";
main();
}
}
else if(command_one=="Quit"){
cout<<"Have a nice day! :D";
}
else{
cout<<"This Option is invalid!\n";
main();
}
}
When it hits the else loop nested in the if(command_one=="One chip") it returns
"This Option is invalid!
One chip, Multi chip, or Quit?
This Option is invalid!
One chip, Multi chip, or Quit?"
But it should be:
"This Option is invalid!
One chip, Multi chip, or Quit?"
How can this be fixed?
main? Generally you would make a new function for this and call it frommain.mainto recurse. By the way this line:double position=slot;don't do anything.