Hey, I just wrote this program when messing about with the FOR and IF commands and I want to know if someone could help me make it look less....well, make it more efficient if you understand what I mean. Thanks in advance.
Code:#include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { string name; string quit; // Just using this to quit the program. string correct; string wrong; cout << "Please enter your name: "; cin >> name; // This is where you put a string into the name variable. cout << "Your name is " << name; cout << ".\n"; // Dumps the variable contents of name to the screen. restart: // Restart point. cout << "Please type Quit and press enter. "; cin >> quit; if (quit == "Quit") // If the user types "quit". { cout << "Thankyou, please type Exit "; // Print message. cin >> correct; if (correct == "Exit") // If user types "exit". { goto exit; // Go to point "exit:" } else // If the user did NOT type "exit" goto restart; } else // If the user did NOT type "quit" cout << "You did not type Quit! .\n"; goto restart; // Go back! exit: // Point exit:. return 0; }




Reply With Quote