Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <string>
- //for (Start value; end condition; increase value)
- using namespace std;
- //first independantly written C++ program. Expect inconstencies. Was mainly to test knowledge and practice C++ :)
- int main()
- {
- //here we have our scope's variables. 1 int and 2 strings.
- int uservalue;
- char answer[4];
- char answer2[4];
- // while(true) means for as long as the function is true then the statement will be ran inside of it.
- while (true)
- {
- //give i a value, once i has a value if that value isn't between 1 and 10 run the first if statement.
- //onec the user gives a value between 1 and 10 run the second part of the if statement.
- cout << "Give i a value between 1 and 10: ";
- cin >> uservalue;
- if (!(uservalue >= 1 && uservalue <= 10))
- {
- cout << "\nSorry, only submit a value between 1 and 10.\n";
- cout << "\nTry again?: ";
- cin >> answer;
- if (answer[1] == 121 || answer[1] == 89 && answer[2] == 101 || answer[2] == 69 && answer[3] == 115 || answer[3] == 83)
- {
- break;
- }
- else
- {
- system("cls");
- }
- }
- else
- {
- //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,
- //then the user will recieve some text with an option to test the program again or not.
- int i = uservalue;
- if (uservalue >= 1 && uservalue <= 10)
- {
- cout << "\nCorrect, the value was between 1 and 10.\n";
- cout << "\nDo you wish to test again?: ";
- cin >> answer2;
- if (answer2[1] == 121 || answer2[1] == 89 && answer2[2] == 101 || answer2[2] == 69 && answer2[3] == 115 || answer2[3] == 83) {
- system("cls");
- }
- else
- {
- break;
- }
- }
- }
- }
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement