Store score with a user profile

  • Thread starter Thread starter GC_-
  • Start date Start date
G

GC_-

Guest
Hi everyone!

I'm fairly new to coding and my professor assigned the class to create a unique program that could be used in real life. I chose to do a user rewards system using 2 forms, one where the customer can register their name and phone number and another where they input their phone number to add reward points to their existing account and display the total points but when they reach past an x amount, they earn a discount code. Our class is not allowed to use databases so I chose do to a text file. I can store the name and phone number but I'm stuck on the point system as the user automatically earns it by typing in their phone number. This is my current code:

public partial class FrmResult : Form
{

// Declare three arrays
string[] fName;
string[] lName;
string[] phonen;

public FrmResult()
{
InitializeComponent();
}

private void FrmResult_Load(object sender, EventArgs e)
{
// Declare variables and constants
string firstName, lastName;
string phone;
string points = 0;
const char DELIM = ',';
string recordIn; // read entire record
string[] fields; // store current record
int sub = 0; // keeps track on which subscript we are on.
const string FILENAME = "userData.txt";
const string FILENAME2 = "permCustData.txt";
const string FILENAME3 = "permDelimData.txt";
int x = 0; // count number of lines
int numRec; // calulate number of records
const int NUM_VAR = 5; //Number of variables

// Create filestream and streamreader
FileStream inFile = new FileStream(FILENAME, FileMode.Open, FileAccess.Read);
StreamReader reader = new StreamReader(inFile);

// Create filestream and streamreader for permanent file
FileStream inFile2 = new FileStream(FILENAME2, FileMode.Open, FileAccess.Read);
StreamReader reader2 = new StreamReader(inFile2);

// Create filestream and streamreader for permanent delimited file
FileStream inFile3 = new FileStream(FILENAME3, FileMode.Open, FileAccess.Read);
StreamReader reader3 = new StreamReader(inFile3);

// Count data in file
while (reader2.ReadLine() != null)
++x;

numRec = x / NUM_VAR;

// Create Arrays
fName = new string[numRec];
lName = new string[numRec];
phonen = new string[numRec];


inFile2.Seek(0, SeekOrigin.Begin);

// Read data from permanent delim file

recordIn = reader3.ReadLine();
while (recordIn != null)
{
fields = recordIn.Split(DELIM); // SEPARATES record
fName[sub] = fields[0];
lName[sub] = fields[1];
phonen[sub] = fields[2];
points[sub] = fields[3];
++sub;
recordIn = reader3.ReadLine();
}
// Read data from file
firstName = reader.ReadLine();
lastName = reader.ReadLine();
phone = reader.ReadLine();
points = Convert.ToInt32(reader.ReadLine());

// close file
reader.Close();
inFile.Close();

// close permanent file
reader2.Close();
inFile2.Close();

// close permanent file
reader3.Close();
inFile3.Close();
}

private void btnEnter_Click(object sender, EventArgs e)
{
bool foundFlag = false; // to keep track if there is a match
int z = 0; // keep position
string nphone; // person is going to type in
int found = 0;

nphone = txtPhone.Text;

for (z = 0; z < fName.Length; ++z)
{
if (nphone == phonen[z])
{
foundFlag = true;
found = z;
}
}
if (foundFlag)
{
points++;
lblResult.Text = String.Format("{0, -10} {1, -15}: You have {2} points", fName[found], lName[found], points.ToString("C"));

}
else
{
lblResult.Text = "Match was not found";
}
}

private void btnRegister_Click(object sender, EventArgs e)
{
FrmRegister secondForm = new FrmRegister();
secondForm.Show();

}
}
}

Continue reading...
 
Back
Top