Hi guys, I need some insight on my code here,
So I have a file that have the following stored:
username password name mobile ic
In this part of my code, I intend to read over this file and identify the username. If the username matches with "inUser" (the username that the user input), I want to retrieve the name, mobile and ic stored in the same line as the matching username.
Upon retrieving the details, i need to assign them to the struct members shown below, which will be stored in a separate file later in the codes.
My problem:
1. I'm pretty sure my while loop to find the username and outputting the name , mobile etc is wrong (bc my compiler popup "logic error") but im not sure how to change it to make it work
2. is this "username password name mobile ic" even a good way of storing data
note that this is not the full code, im only testing it and i am not supposed to use vector pointer etc.
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
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
//I need these global variables bc i will be using it across functions
int Choice1;
int Mobile, Ic;
string User, Pass, Name, inUser, inPass;
struct Customer {
string user, pass, name;
int mobile, ic;
}customer;
struct Booking {
Customer customer;
int day, month, year;
double start, end, price;
string dayOfWeek; // not used here
};
Booking booking[200][5] = { 0 };
int main()
{
inUser = "jojo"; // I just assume the user input "jojo" here
bool status = false;
ifstream c("customer.txt");
if (!c)
cout << "Unable to open file!\n";
else
while(!status && (c >> User >> Pass >> Name >> Mobile >> Ic))
status = (inUser == User); //loop until they matches
//after reading the relevant details from customer files, assign the name, mobile and ic to the struct members
booking[1][1].customer.user = User;
booking[1][1].customer.name = Name;
booking[1][1].customer.mobile = Mobile;
booking[1][1].customer.ic = Ic;
c.close();
//just to check if it works or not
cout << booking[1][1].customer.user << endl;
cout << booking[1][1].customer.name << endl;
cout << booking[1][1].customer.mobile << endl;
cout << booking[1][1].customer.ic << endl;
system("pause");
return 0;
}
|