Advertisement
Guest User

dwwwwwwww

a guest
Apr 25th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4. //for (Start value; end condition; increase value)
  5. using namespace std;
  6. //first independantly written C++ program. Expect inconstencies. Was mainly to test knowledge and practice C++ :)
  7. int main()
  8. {
  9.     //here we have our scope's variables. 1 int and 2 strings.
  10.     int uservalue;
  11.     char answer[4];
  12.     char answer2[4];
  13.     // while(true) means for as long as the function is true then the statement will be ran inside of it.
  14.     while (true)
  15.     {
  16.         //give i a value, once i has a value if that value isn't between 1 and 10 run the first if statement.
  17.         //onec the user gives a value between 1 and 10 run the second part of the if statement.
  18.         cout << "Give i a value between 1 and 10: ";
  19.         cin >> uservalue;
  20.         if (!(uservalue >= 1 && uservalue <= 10))
  21.         {
  22.             cout << "\nSorry, only submit a value between 1 and 10.\n";
  23.             cout << "\nTry again?: ";
  24.             cin >> answer;
  25.     if (answer[1] == 121 || answer[1] == 89 && answer[2] == 101 || answer[2] == 69 && answer[3] == 115 || answer[3] == 83)
  26.             {
  27.                 break;
  28.             }
  29.             else
  30.             {
  31.                 system("cls");
  32.             }
  33.         }
  34.         else
  35.         {
  36.             //the int i is assigned the passed through value that's between 1 and 10 and if that's correct (which it has to be in order to get to this part of the loop,
  37.             //then the user will recieve some text with an option to test the program again or not.
  38.             int i = uservalue;
  39.             if (uservalue >= 1 && uservalue <= 10)
  40.             {
  41.                 cout << "\nCorrect, the value was between 1 and 10.\n";
  42.                 cout << "\nDo you wish to test again?: ";
  43.                 cin >> answer2;
  44. if (answer2[1] == 121 || answer2[1] == 89 && answer2[2] == 101 || answer2[2] == 69 && answer2[3] == 115 || answer2[3] == 83)                {
  45.                     system("cls");
  46.                 }
  47.                 else
  48.                 {
  49.                     break;
  50.                 }
  51.             }
  52.         }
  53.     }
  54.  
  55.     _getch();
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement