Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Das Hauptprogramm
- int main(){
- int control = 0; // First state
- int nextYes, nextNo; // To decide the state from the answer
- bool getInput = true; // So we can skip yes / no from the user to show different paths
- string userInput; // The cin from the user is written to this string
- cout << "The friendship algortihm!" << endl << endl;
- while (control != 99){
- switch (control) {
- case 0:
- cout << "Place phone call!" << endl;
- cout << "Is someone at home?" << endl;
- nextYes = 2;
- nextNo = 1;
- break;
- case 1:
- cout << "Leave message!" << endl;
- cout << "Wait for callback.." << endl;
- getInput = false;
- control = 0;
- break;
- case 2:
- cout << "Hey would you like to share a meal some time?" << endl;
- nextYes = 3;
- nextNo = 4;
- break;
- case 3:
- cout << "Dine together!" << endl;
- control = 99;
- getInput = false;
- break;
- case 4:
- cout << "Do you enjoy a hot beverage?" << endl;
- nextYes = 5;
- break;
- case 5:
- cout << "What would you like to drink?" << endl;
- bool correctInput = false;
- while (!correctInput) // Loop while NOT a correct input ("!" means not)
- {
- cout << "Choose between tea, coffee and cocoa!" << endl;
- cin >> userInput;
- if (userInput == "tea")
- correctInput = true;
- else if (userInput == "coffee")
- correctInput = true;
- else if (userInput == "cocoa")
- correctInput = true;
- }
- cout << "Have " << userInput << endl;
- control = 99;
- break;
- // If we need a new input we ask for it
- if (getInput)
- {
- cin >> userInput;
- if (userInput == "yes")
- {
- control = nextYes;
- }
- else if (userInput == "no")
- {
- control = nextNo;
- }
- else
- cout << "Please write yes or no!" << endl;
- }
- getInput = true; // Enables input for next question if needed
- }
- }
- cout << "Begin friendship! <3" << endl; // The goal <3
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement