Sorry for the long code, im trying to make this program loop up to the top after the user enters that they would like to continue, but I can't figure it out. Area i attempted to make the program repeat is at the bottom of the code
int main()
{
//declare variables
string picture = "";
string Next = "";
//colors 1-blue 2-green 3-cyan 4-purple
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
cout << "Which picture would you like to see? " << endl;
cout << "Type Witch, Pumpkin, or Ghost: " << picture;
One small thing..
Regardless of the elseif(exit == "Next") the while will go into its next iteration so the condition is not required.
And also if (transform(exit.begin(), exit.end(), exit.begin(), toupper) == "STOP") can be used instead of if (exit == "Stop") just like how you did it with picture, to make sure that the user doesn't have to type exact cases. ;)
keskiverto's approach is pretty neat but yours is fine too.
One more thing.
Please, use code tags <> when posting code. See http://www.cplusplus.com/articles/jEywvCM9/
Systematic&intuitive indentation&whitespace is important too. It helps to see the logic.
For example, your post ends:
1 2 3 4 5 6 7 8 9 10 11 12
string exit = "Stop";
cin >> exit;
if (exit == "Stop")
return 0;
elseif (exit == "Next")
//repeat @ begining of int main () <---------------------------------
system("pause");
return 0;
} //end while
} //end of main function
The comment tells that brace on line 11 is the end of some loop, but I won't trace it now. Not from that unindented post.
IF line 4 test is true THEN line 5 ends the entire program.
IF line 6 test is true THEN line 8 runs the external program.
Line 10 ends the entire program regardless of what the user input was.
What is the point of a loop, if you will bail out on first time?
1 2 3 4 5 6 7 8 9 10 11 12
while ( cond ) {
// code
return 0;
}
return 0;
// does in practice same as
if ( cond ) {
// code
}
return 0;