Any easier way to do that?

I'm using windows 8 and my taskbar keeps filling up with games, so i decided to write a program from where i can open all of the games. I'm just wondering if there's a faster or more compact way of doing that?


Code so far:
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
  #include <conio.h>
#include <iostream>
#include <Windows.h>
using namespace std;

int main()
{
	int game;
	
	cout << "Choose a game\n";
	cout << "1. Toribash\n2. FarCry 3\n3. Terraria\n4. Assassin's Creed III\n5. Need For Speed: THE RUN\n6. Assassin's Creed IV\n7. Saints Row IV\n8. The Sims 3\n9. Torchlight 2\n10. Dragons Prophet\n11. The Movies\n";
	cin >> game;

	if (game == 1)
	{
		cout << "Opening Toribash" << endl;
		system("\"D:\\Games\\Toribash-4.5\\toribash.exe\"");
		return 0;
	}

	
	if (game == 2)
	{
		cout << "Opening FarCry 3" << endl;
		system("\"D:\\Games\\FarCry 3\\bin\\farcry3.exe\"");
		return 0;
	}
	
	if (game == 3)
	{
		cout << "Opening Terraria" << endl;
		system("\"D:\\Games\\Terraria\\Terraria\\Terraria.exe\"");
		return 0;
	}
	if (game == 4)
	{
		cout << "Opening Assassin's Creed III" << endl;
		system("\"D:\\Games\\Assassin's Creed III\\AC3SP\"");
		return 0;
	}
	if (game == 5)
	{
		cout << "Opening Need For Speed: THE RUN" << endl;
		system("\"D:\\Games\\Need for Speed The Run\\Need For Speed The Run\"");
		return 0;
	}
	if (game == 6)
	{
		cout << "Opening Assassin's Creed IV" << endl;
		system("\"D:\\Games\\Assassins Creed IV Black Flag\\AS4BFSP\"");
		return 0;
	}
	if (game == 7)
	{
		cout << "Opening Saints Row IV" << endl;
		system("\"D:\\Games\\Saints Row IV\\SaintsRowIV\"");
			return 0;
	}
	if (game == 8)
	{
		cout << "Opening The Sims 3" << endl;
		system("\"D:\\Games\\The Sims 3\\Game\\Bin\\TS3\"");
		return 0;
	}
	if (game == 9)
	{
		cout << "Opening Torchlight 2" << endl;
		system("\"D:\\Games\\Torchlight 2\\Torchlight2\"");
		return 0;
	}
	if (game == 10)
	{
		cout << "Opening Dragons Prophet" << endl;
		system("\"D:\\Games\\Dragons Prophet\\launchPad.exe\"");
		return 0;
	}
	if (game == 11)
	{
		cout << "Opening Dragons Prophet" << endl;
		system("\"D:\\Games\\The Movies\\MoviesSE\"");
		return 0;
	}
	system("pause");
	return 0;
}
Last edited on
use a switch statement, or at the very least if..else statements, rather than just if statements.
like that?
1
2
3
4
5
6
7
8
9
10
11
switch (game)
	{
	case 1:
		cout << "Opening Toribash" << endl;
		system("\"D:\\Games\\Toribash-4.5\\toribash.exe\"");
		break;
	case 2:
		cout << "Opening FarCry 3" << endl;
		system("\"D:\\Games\\FarCry 3\\bin\\farcry3.exe\"");
		break;
	}
yep :)
You can then use the default case to handle if the user enters 27 or something. ('Game does not exist' etc etc).
Last edited on
Make a cout function too so you don't have to write the extra lines.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void WriteLine(string line, ostream& out = cout) {
        out << line << endl;
}

switch(game) {

    case 1: WriteLine("Opening Toribash"); 
          break;
}


// If you need to write to a file
fstream outFile;
outFile.open("some_file");

WriteLine("Opening Toribash", outFile);

i don't understand anything IceThatJaw :D (WriteLine thing)
Last edited on
Is there a way to make it possible to add games from the program itself instead of changing the code manually?

maybe something like
1
2
3
4
5
6
7
8
Choose a game

1...
2...
3...
4...

5. Register new game


when you select 5
1
2
3
4
5
6
7
cin << name;
cout << "name: " << name << endl;

//path of the game launcher
cin << path;
cout << "path: " << path << endl;


and then it throws you back to the main menu but now it's
1
2
3
4
5
6
7
1...
2...
3...
4...
5... //new game

6. Register new game

Use a .txt file.
just like what IceThatJaw said, use a text file to store list of games you currently have,
then retrieve it or add something to it at runtime

http://www.cplusplus.com/doc/tutorial/files/
Topic archived. No new replies allowed.