View difference between Paste ID: SLk1wtK9 and y80cGAji
SHOW: | | - or go back to the newest paste.
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];
11+
	char answer[4];  //chars are great for both numbers and letters because you can check every each letter/number like shown in here
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
// basically what happens here is we check the answer using ascii tables, 121 is "y" and 89 is "Y", 101 "e" 69"E", 115 "s" 83 "S"
27
//the idea behind this is to check every single letter in the input, instead of doing "yes || Yes || YEs|| YES|| yEs || yES || yeS"
28
			{
29
				break;
30
			}
31
			else
32
			{
33
				system("cls");
34
			}
35
		}
36
		else
37
		{
38
			//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,
39
			//then the user will recieve some text with an option to test the program again or not.
40
			int i = uservalue;
41
			if (uservalue >= 1 && uservalue <= 10)
42
			{
43
				cout << "\nCorrect, the value was between 1 and 10.\n";
44
				cout << "\nDo you wish to test again?: ";
45
				cin >> answer2;
46
if (answer2[1] == 121 || answer2[1] == 89 && answer2[2] == 101 || answer2[2] == 69 && answer2[3] == 115 || answer2[3] == 83)				{
47
					system("cls");
48
				}
49
				else
50
				{
51
					break;
52
				}
53
			}
54
		}
55
	}
56
57
	_getch();
58
	return 0;
59
}