Adding score to scoreboard from a game.

The game basically spins a slot machine and the user acquires points depending on the result. So far, the user successfully gets the right amount of points depending on the result of the spin but I want those points to be written to a file "userStats.txt" along with their username. Any ideas?

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
#include <iostream>
#include <string>
#include <iomanip>
#include <ctime>
#include <fstream>


using namespace std;

enum Options { TOMATO, ORANGE, APPLE, PINEAPPLE, STRAWBERRY, GRAPES };
Options posOne = TOMATO;
Options posTwo = APPLE;
Options posThree = GRAPES;


const int MILIDELAY = 1; //defines the delay in miliseconds as a constant
const int NUMSPINS = 50; //defines the number of time to spin the slot machine as a constant

void menu();
char choice;
int point;

string outputOptions(Options x); //Returns the string equivalent of the enum type Options value
void spinning();
void getPos(Options& x); //This function cycles through the Options values
void delay(); //delays the output by the number of miliseconds as defined by the constant MILIDELAY
void spinMachine(Options& One, Options& Two, Options& Three); //Simulates the spinning of the slot machine for a specifed number of spins as defined by NUMSPINS
void getStopOrder(int& first, int& second, int& last);
int getScore(Options posOne, Options posTwo, Options posThree);

void game2Text();
void game3Text();
int game1(); // Choice 1 
void game2(); // Choice 2
void game3(); // Choice 3
void menuScore(); // Choice 4


void selectionSort(int list[], string users[], int length);
void loadData(int list[], string users[], int lenght, char game);
void writeData(int list[], string users[], int lenght, char game);
void deleteUser(int list[], string users[], int lenght, int deleteIndex);

int main()
{
	menu();
}

void menu()
{
	char menuChoice = 'z';
	cout << " -----Welcome to the main menu-----\n";
	cout << " Press 1 for game 1\n";
	cout << " press 2 for game 2\n";
	cout << " press 3 for game 3\n";
	cout << " press 4 for Score menu\n";
	cout << " press F to exit program\n";

	cin >> menuChoice;
	
	while (menuChoice != 'f')
	{
		switch (menuChoice)
		{
		case '1':
			game1(); // menu choice game 1
			break;
		case '2':
			game2(); // menu choice game 2
			break;
		case '3':
			game3(); // menu choice game 3
			break;
		case '4':
			menuScore(); // menu for checking score
			break;
		default:
			cout << "Thank you for playing. ";
		}
	} // End while
	cout << endl;
}

int game1()
{
	spinning();

	return choice;

int getScore(Options posOne, Options posTwo, Options posThree)
{
	if (posOne == posTwo || posTwo == posThree)
	{
		point = (point + 3);
	}
	else if (posOne == posTwo || posOne == posThree || posTwo == posThree)
	{
		point = (point + 10);
	}

	return point;
}

void spinning()
 {
		//defines three spinning position each starting with a different value
		Options posOne = TOMATO;
		Options posTwo = APPLE;
		Options posThree = GRAPES;
		char userChoice = 'z';

		while (userChoice != 'n')
		{
			spinMachine(posOne, posTwo, posThree); //spins the slotmachines positions
			getScore(posOne, posTwo, posThree); //adds score per spin

			cout << "\nWould you like to spin again? (y/n): \n";
			cin >> userChoice;

			if (userChoice == 'y')
			{
				cout << " You now have: " << point << " points\n" << endl;
			}
			else if (userChoice == 'n')
				cout << " Thank you for playing, you now have: " << point << " points\n" << endl;
		}
		
	}

	
Topic archived. No new replies allowed.