Simple code from beginner. Need few advises on the code.

Hi guys,

I recently started learning C++ and was able to write a simple code.

Would you please review it if possible and advise if anything should be written differently?

The base of the code is to open a simple Menu in which we can choose an option that will be then progressed accordingly. All is connected with a loop, so after one completion, we are being moved back to main page.

For lottery for example, I am unable to figure out how to exclude duplicates from appearing.

Additionally I have noticed that If I choose option "Load data" when there is no file, the cmd window closes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
 #include <iostream>
#include <fstream>
#include <cstdlib>
#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include <time.h>

using namespace std;

float x, y;

char choice;
char another_choice;

int number, tryy, choice_number=0;
int another_number;

string login, pass;
string name, surname;
int tel_number;

int main()
{

        for(;;)
    {

    cout << "We live in a simulation..." << endl;

    cout << endl;
    cout << "MAIN MENU" << endl;
    cout << "------------" << endl;
    cout << "1. Log in" << endl;
    cout << "2. Play" << endl;
    cout << "3. Count" << endl;
    cout << "4. Lottery" << endl;

    cout << "5. Save data" << endl;
    cout << "6. Load data" << endl;

    cout << "------------" << endl;
    cout << "7. Close" << endl;

    cout << endl;

    cout << "Choose: ";
    choice = getch();

    cout << endl;

        switch(choice)
    {
    case '1': //Login script
        {
                cout << "Enter login:" << endl;
    cin >> login;
    cout << "Enter password:" << endl;
    cin >> pass;

    if ((login=="admin")&&(pass=="adminpassword"))
    {
        cout << "Logged successfully";
    }
    else
    {
        cout << "Incorrect data, please try again.";
    }
        }
    break;

    case '2': //Guess game
        {
                cout << "Hello! I have chosen a number from 1 to 100. Can you guess?"  << endl;
    srand(time(NULL));
    number = rand()%100+1;

    while(tryy!=number)
    {
        choice_number++;
        cout << "Guess a number (this is Yours " << choice_number << " try): ";
        cin >> tryy;

        if(tryy==number)
            cout << "You have guessed in " << choice_number << " try/tries! You have won! " << endl;
        else if(tryy<number)
            cout << "Not enough!" << endl;
        else if(tryy>number)
            cout << "Too much!" << endl;
    }

    system("pause");

        }
    break;

    case '3': // simple calculator
        {

     cout << "Enter 1st number: ";
    cin >> x;
    cout << "Enter 2nd number: ";
    cin >> y;

    cout << endl;
    cout << "Choose from below:" << endl;
    cout << "------------" << endl;
    cout << "1. Addition" << endl;
    cout << "2. Subtraction" << endl;
    cout << "3. Multiplication" << endl;
    cout << "4. Division" << endl;

    cout << "Choose: ";
    another_choice = getch();

    switch(another_choice)
    {
    case '1':
        {
            cout << "Result = " << x+y;
        }
    break;
    case '2':
        {
            cout << "Result = " << x-y;
        }
    break;
    case '3':
        {
            cout << "Result = " << x*y;
        }
    break;
    case '4':
        {
            if (y==0) cout << "We do not divide by 0";
            else cout << "Result = " << x/y;
        }
    break;

    default: cout << "Incorrect option chosen!";
    }
        }
    break;

    case '4': //lottery. I was unable to exclude duplicates.
        {
                cout << "Welcome to Lottery! In three seconds we will start. Duplicates may occur." << endl;
    Sleep(3000);

    cout << endl;
    srand(time(NULL));
    for (int i=1; i<=6; i++)
    {
    another_number = rand()%49+1;
    Sleep(1000);
    cout << another_number << "\a" << endl;
    }
        }
    break;
    case '5': //save data to TXT file
        {
    cout << "Enter name: ";
    cin >> name;
    cout << "Enter surname: ";
    cin >> surname;
    cout << "Enter phone number: ";
    cin >> tel_number;

    fstream file;
    file.open("savefile.txt",ios::out | ios::app);

    file<<name<<endl;
    file<<surname<<endl;
    file<<tel_number<<endl;

    file.close();
        }
    break;

    case '6': // Load data from TXT file
        {

    fstream file;
    file.open("savefile.txt",ios::in);

    if(file.good()==false)
    {
        cout << "File does not exist!";
        exit(0);
    }
    string line;
        int line_number=1;

    while(getline(file,line))
    {

        switch(line_number)
        {
            case 1: name = line;
            break;

            case 2: surname = line;
            break;

            case 3: tel_number = atoi(line.c_str());
            break;
        }


        line_number++;
    }

    file.close();

    cout<<name<<endl;
    cout<<surname<<endl;
    cout<<tel_number<<endl;

        }
    break;

            case '7': //close
                exit(0);
            break;

    default: cout << "Option not available!";
    }
    getchar();getchar();
    system("cls");
}

    return 0;
}
Last edited on
After a quick look I recommend:
- Get rid of all the global variables and declare them inside main.
- Learn and use functions so you can structure your code better.
- To avoid duplicates you could use a std::set
Hello blade007zg,

Starting from the top:

Your header files "iostream" and "fstream" are OK."cstdlib" is the correct useage for this header file, but its use is 50/50 for including it. There are other header file that will include "stdlib.h" without you knowing it. Although some people will tell you that it is best to include all the header files that you will need. This is OK too.

"windows.h" tends to limit who can compile and run your code. I would say that anyone not using the "Windoes" operating system is likely to have a problem with the program. If this program is for your own use or for school, who uses "Windows" then it is fine. Just keep in ind that "windows.h" is not a standard C++ header file.

"conio.h" again this is not a standard C++ header file and that it is old and out dated along with newer compilers do not even include this file with their standard setup. This is fine for your own use, not everyone can use it.

"stdio.h" is s C file for input and output that you have already covered with "iostream".

"time.h" is OK, but you should use "ctime" instead."ctime" is the C++ header file.

The line using namespace std; should not be used because it WILL give you problems some day. Just starting it is better to learn what is in the standard namespace and how to qualify them. For now what you are most likely to use is "std::cin", "std::cout" and "std::endl" and with the use of "fstream" "std" "ifstream" and "std::ofstream" for use with files.

These days "double" is preferred over float. The short answer is that a "double" will store a number better than a "float" and give more accurate results in calculations. If you need more information let me know.

As Thomas1965 said your global variables are better put in main. As global variable anything in the file has the ability to change the and it becomes a potential problem. With your program the way it is it is still a potential problem, but better. Anything that you would put as a global variable should start with "const" or the newer version "constexpr". After the type the variable should be in all caps to remind you that it is a constant that can not be changed. An example: constexpr size_t MAXSIZE{ 10 };. You can think of "size_t" as another name for "unsigned int" which you will learn is a return value for many functions that you will use. You can also write "std::size_t", but the "std::" is not always needed, but may be a good habit to get into.

As a global variable "MAXSIZE" can be used through out the file, but is most often used to define an array, i.e.,
int numArray[MAXSIZE]{}. This way to change the array size you only have one place to go to change the size and since it is near the top of your program it is easy to find. Do not feel that you have to use "MAXSIZE". This name can be anything that describes what it is used for. Read enough here and you will see that "MAXSIZE" is most often used.

With that said the use of the "_" in the variable name is OK, but the use of camel case is more often used these days, so another_choice would become anotherChoice. What I do and some of this may be my choice is that a regular variable starts with a lower case letter. I use an upper case letter when I define a "class", "function" or "struct" to set them apart from regular variables. I use all upper case letters when I define a variable as a constant, like "MAXSIZE"

I will take this time to say that it is a good idea to initialize your variables. With the use of the "uniform initializer" the {}, it is easy int num; becomes int num{};. The empty {}s will initialize integer types to zero and floating point types, i.e., "double"s and "float"s to 0. and "char"s to '\0'. the "std::string" along with "vector"s, "list"s and others are defined as empty and do not need initialized. Some people have said that you do not need to initialize variables when they are defined which does work most of the time, but there are occasions when it is necessary to give a variable a value before it is used.

I will say this when a variable is defined memory is set aside for that variable, but the "1"s and "0"s that are left there from some other use are known as "garbage" or a "garbage value" and have no real value to your program and could potentially cause a problem in your program later.

This may be a personal preference of mine, but I like to define may variables at the top of the function be it "main" or some other function. I also like to group the variables, i.e., keep "int"s and the like together then "double"s, "char"s and "string"s. I generally end up putting"bool"s last then things like "class"es and "struct"s. Sometimes I put "class"es and "struct"s first. Some people will tell you to define variables just before they are used, but this can make them hard to find in the program. That is why I put them at the beginning of a function where they are easy to find.

Inside "main" the endless for loop works, but a do/while loop is a better choice. This is what I like to do with a do/while loop:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <cctype>  // <--- For tolower() and toupper().

int main()
{
	char ans{};
	bool cont{ true };

	do
	{
		// Code here.

		std::cout << "Do another Y/N: ";  // <--- Change message to what you want.
		std::cin >> ans;
		ans = std::toupper(ans);

                if (ans == 'N')
                    cont = false;

	} while (cont);
}

As Thomas1965 said you should learn how to use functions. You can read about them here: http://www.cplusplus.com/doc/tutorial/functions/ To that end I would not only put the menu in a function I would also validate the choice and only return a valid choice.

The use of "getch()" is something you and I could use, but not everyone can and on my computer I have to use getch()" for it to work because "getch()" is out dated. A better choice hare is std::cin >> choice and that would probably need to be followed with
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>. to clear the input buffer of the new line character left there by the "stdcin >>". I will know more when I have a chance to test the program.

The use of the "switch"s are a good choice. I have with my VS IDE the case statements do not indent the way I would like, so I have to indent the case statements once i first get started to make it easier to read.

Looking through the case statements I see "srand()" this should be at the top of "main" and only done once not ease time you call that case statement. I usually write that line as: srand(static_cast<std::size_t>(time(NULL))); This has always worked for me, but may not be 100% correct.

Your variable "tryy" as you most likely found out that "try" is a reserved key word of "try/catch", but I would come up with a better name. Something that describes what it does would be nice.

I see "system("pause");" and "system("cls")" both and anything "system" should be avoided. For you own use it is OK, but try to avoid using "system". For "pause" I use:
1
2
3
4
// The next line may not be needid. If you have to press enter to see the prompt it is not needed.
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.
std::cout << "\n\n Press Enter to continue";
std::cin.get();

And for 'cls" I have a function that I use. If you would like it let me know.

Again in "case 3:" for the menu I would put this in a function returning a valid choice to use in the switch.

BTW in the switch/case statements the {}s for the case statements are not needed unless you are defining a variable inside the case staatement which means that you are most likely doing something wrong.

End part 1.
Part 2

When you define the file stream, as in case 5, you should use "ofstream" although there is nothing wrong with what you did. Using "ofstream" you would not need the "ios::out" in the open statement.

In case 6 you could use "ifstream"to define the file. Again there is nothing wrong with what you did it works.

Both "ifstream" and "ofstream" come from the 'fstream" header file. Nothing extra that you need to do.

In case 6 the if statement to check if the file is open can be shortened to:
1
2
3
4
5
if (!file)
{
	cout << "File does not exist!";
	exit(1);  // <--- 1 or any number > 0 means that there is a problem.
}

In case 6 the while condition is written correctly for reading the file.

Case 7 the "exit(0)" works, but not the best way to end the program.

Not sure what the two "getchar()"s are for, but you could use what I showed you earlier.

I will work on your code and show you what it could look like.

Hope that helps,

Andy
Hello blade007zg,

I promised you some code and I am sorry it has taken me so long to post it.

The main file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <chrono>
#include <thread>

//using namespace std;

// <--- Proto types.
size_t MainMenu();
void GuessNumner();
void WaitForEnter(const int choice);

constexpr int USERTRY{ 7 };

int main()
{

	int number{}, choiceNumber{};
	int anotherNumber{};
	int anotherChoice{};
	std::size_t choice{};

	double x{}, y{};


	std::string login, pass;
	std::string name, surname, telNumber;

	bool cont{ true };

	srand(static_cast<std::size_t>(time(NULL)));

	do
	{
		//CLS;  // <--- My way to clear the screen

		choice = MainMenu();

		std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.
		std::cout << std::endl;

		switch (choice)
		{
			// <--- Needs work. Either way the if statement will allow the program will continue.

		case 1: //Login script
		{
			std::cout << "Enter user name: ";
			std::cin >> login;
			std::cout << "Enter password: ";
			std::cin >> pass;

			if ((login == "admin") && (pass == "adminpassword"))
			{
				std::cout << "Logged successfully";
			}
			else
			{
				std::cout << "\n Incorrect data, please try again.\n";
				std::this_thread::sleep_for(std::chrono::seconds(3));  // Requires header files "chrono" and "thread"
				exit(1);
				// <--- Or you could do a loop giving 3 tries and "exit" after the 3rd try.
			}
		}
		break;

		case 2: //Guess game
		{

			GuessNumner();

			WaitForEnter(choice);
		}
		break;

		case 3: // simple calculator
		{
			std::cout << "Enter 1st number: ";
			std::cin >> x;
			std::cout << "Enter 2nd number: ";
			std::cin >> y;

			// <--- Best to put the menu in a function. Like I did with the MainMenu() function.
			std::cout << std::endl;
			std::cout << "Choose from below:" << std::endl;
			std::cout << "------------" << std::endl;
			std::cout << "1. Addition" << std::endl;
			std::cout << "2. Subtraction" << std::endl;
			std::cout << "3. Multiplication" << std::endl;
			std::cout << "4. Division" << std::endl;

			std::cout << "Choose: ";
			std::cin >> anotherChoice;

			switch (anotherChoice)
			{
			case 1:
				std::cout << "Result = " << x + y;
			break;
			case 2:
			{
				std::cout << "Result = " << x - y;
			}
			break;
			case 3:
				std::cout << "Result = " << x * y;  // <--- Watch spacing. This looks better.
			break;
			case 4:
				if (y == 0)  // <--- One line is OK, but this reads better.
					std::cout << "We do not divide by 0";
				else
					std::cout << "Result = " << x / y;
			break;

			default: std::cout << "Incorrect option chosen!";
			}
		}

		WaitForEnter(choice);
		break;

		case 4: //lottery. I was unable to exclude duplicates.
			std::cout << "Welcome to Lottery! In three seconds we will start. Duplicates may occur." << std::endl;
			std::this_thread::sleep_for(std::chrono::seconds(3));  // Requires header files "chrono" and "thread";

			std::cout << std::endl;
			// *******************************
			for (int i = 1; i <= 6; i++)
			{
				anotherNumber = rand() % 49 + 1;
				std::this_thread::sleep_for(std::chrono::seconds(1));  // Requires header files "chrono" and "thread";
				std::cout << anotherNumber << "\a" << std::endl;
			}
			WaitForEnter(choice);
			break;

		case 5: //save data to TXT file
		{
			std::cout << "Enter name: ";
			std::getline(std::cin, name);

			std::cout << "Enter surname: ";
			std::getline(std::cin, surname);

			std::cout << "Enter phone number: ";  //<--- needs example of how to enter the phone number.
			std::getline(std::cin, telNumber);  // <--- Made telNumber a "std::string" so Phone number can be
												// entered in any way.
												// <--- Otherwise "telNumber" would have to be a "long long" or "unsigned long long" to hold a
												// number like "9375559999". This number is much bigger than an "int" can store.

												// ********************************************************
			std::ofstream file;
			file.open("savefile.txt", std::ios::app);

			file << name << std::endl;
			file << surname << std::endl;
			file << telNumber << std::endl;

			file.close();
		}
		break;

		case 6: // Load data from TXT file
		{

			std::ifstream file;
			file.open("savefile.txt");

			if (file.good() == false)
			{
				std::cout << "File does not exist!";
				exit(0);
			}
			std::string line;
			int line_number = 1;

			while (std::getline(file, line))
			{

				switch (line_number)
				{
				case 1: name = line;
					break;

				case 2: surname = line;
					break;

				case 3: telNumber = line; // atoi(line.c_str());
					break;
				}

				line_number++;
			}

			file.close();

			std::cout << name << std::endl;
			std::cout << surname << std::endl;
			std::cout << telNumber << std::endl;

			WaitForEnter(choice);
		}
		break;

		case 7: //close
			cont = false;
			break;

		default: std::cout << "Option not available!";
		}

		// The next line may not be needid. If you have to press enter to see the prompt it is not needed.
		//std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.
		//std::cout << "\n\n Press Enter to continue";
		//std::cin.get();

		//CLS;
		system("cls");
	} while (cont);

	return 0;
}
size_t MainMenu()
{
	std::size_t choice{ 1 };
	bool cont{ true };

	do
	{
		std::cout << "We live in a simulation..." << std::endl;

		std::cout << std::endl;
		std::cout << "MAIN MENU" << std::endl;
		std::cout << "------------" << std::endl;
		std::cout << "1. Log in" << std::endl;
		std::cout << "2. Play" << std::endl;
		std::cout << "3. Count" << std::endl;
		std::cout << "4. Lottery" << std::endl;

		std::cout << "5. Save data" << std::endl;
		std::cout << "6. Load data" << std::endl;

		std::cout << "------------" << std::endl;
		std::cout << "7. Close" << std::endl;

		std::cout << std::endl;

		std::cout << "Choose: ";
		std::cin >> choice;

		if (choice > 0 && choice < 8)
			cont = false;
		else
		{
			std::cout << "\n Invalid choice try again:";
			std::this_thread::sleep_for(std::chrono::seconds(3));  // Requires header files "chrono" and "thread"
		}
	} while (cont);

	return choice;
}

void GuessNumner()
{
	int computerGuess{}, userGuess{};
	int userTry{ 1 };  // <--- Needs to start at 1.
	std::string sUserTry;  // <--- The beginning "s" is to denote that it is a "std::string".

	std::cout << "\n Hello! I have chosen a number from 1 to 100. Can you guess?" << std::endl;

	computerGuess = rand() % 100 + 1;

	//std::cout << computerGuess << '\n';  // <--- Used for testing.

	while (userGuess != computerGuess && userTry <= USERTRY)
	{

		//if (userTry >= USERTRY)
		//	break;

		switch (userTry)
		{
		case 1:
			sUserTry = "st";
			break;
		case 2:
			sUserTry = "nd";
			break;
		case 3:
			sUserTry = "rd";
			break;
		case 4:
		case 5:
		case 6:
		case 7:
			sUserTry = "th";
			break;
		default:
			break;
		}

		std::cout << "\n Guess a number (this is Yours " << userTry << sUserTry << " try): ";
		std::cin >> userGuess;

		if (userGuess == computerGuess)
		{
			std::cout << "\n You have guessed in " << userTry << (userTry > 1 ? " tries! You have won! " : " try! You have won! ") << std::endl;
			userTry = 7;
			break;
		}
		else if (userGuess < computerGuess)
			std::cout << "Not enough!" << std::endl;
		else if (userGuess > computerGuess)
			std::cout << "Too much!" << std::endl;

		userTry++;  // <--- Better done at the end of the while loop.
	}

	//std::cout << '\n' << userTry << '\n';  // <--- Used for testing.

	if (userTry > USERTRY)
		std::cout << "\n You have exceeded you number of tries.\n\n Please try again.\n" << std::endl;
}

void WaitForEnter(const int choice)
{
	// The next line may not be needid. If you have to press enter to see the prompt it is not needed.
	if (choice != 6)
		std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.
	std::cout << "\n\n Press Enter to continue";
	std::cin.get();
}


continued...
What did not fit in the first message.

What I use to clear the screen:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
void cls()
{
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD coordScreen = { 0, 0 };    /* here's where we'll home the
										cursor */
	BOOL bSuccess;
	DWORD cCharsWritten;
	CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
	DWORD dwConSize;                 /* number of character cells in
										the current buffer */

										/* get the number of character cells in the current buffer */

	bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);
	PERR(bSuccess, "GetConsoleScreenBufferInfo");
	dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

	/* fill the entire screen with blanks */

	bSuccess = FillConsoleOutputCharacter(hConsole, (TCHAR) ' ',
		dwConSize, coordScreen, &cCharsWritten);
	PERR(bSuccess, "FillConsoleOutputCharacter");

	/* get the current text attribute */

	bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);
	PERR(bSuccess, "ConsoleScreenBufferInfo");

	/* now set the buffer's attributes accordingly */

	bSuccess = FillConsoleOutputAttribute(hConsole, csbi.wAttributes,
		dwConSize, coordScreen, &cCharsWritten);
	PERR(bSuccess, "FillConsoleOutputAttribute");

	/* put the cursor at (0, 0) */

	bSuccess = SetConsoleCursorPosition(hConsole, coordScreen);
	PERR(bSuccess, "SetConsoleCursorPosition");
	return;
}  //  End CLS 


When used in a program I use "CLS", that I have commented out in the above code. In a header file I include there is a line "#define CLS cls()". You could put this in the main file or in a different header file if you know how to do that.

As you can see I have only put "case 2" in a function, but cases 3, 4, 5 and 6 could be put in functions also. Because I used the code I did to pause the program I put that in a function also. I had to add the if statement to the "WaitForEnter" function because case 6 is different. I could have left out the if statement and just put the 4 lines at the end of case 6 because it is different.

Any questions let me know.

Hope this helps,

Andy
Hi Guys,

Seriously, thank you all for your help with this.
Obviously I have still a lot of work, but with your pointers, I believe I have noticed most of the issues.

Thank you again.

Once I learn a bit more and polish what I know already, I will ask you to review a new code.

One more time, thanks for help:)

Regards,

Artur
Topic archived. No new replies allowed.