Hi,
I am having trouble with skipping lines in a file and inputting the value it reads into variable inside the program.
Data Inside the txt file i am trying to read:
00112
yourname
5874.87
176.07
3456.98
what i want to do is take the last 3 numbers and input each into a variable
here is what i have so far:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void search(char& accntt, char& passt, string accnt, string pass);
void get_bal(double& savbal, double& chekbal, double& cdbal);
int main()
{
char accntt, passt;
double savbal, chekbal, cdbal;
string accnt, pass;
cout << "Please enter your account number.\n";
cin >> accnt;
cout << "Please enter your password.\n";
cin >> pass;
search(accntt, passt, accnt, pass);
if(accntt == 't' && passt == 't')
{
get_bal(savbal, chekbal, cdbal);
}
//cout <<"Data 0:" << data[0] << endl << "Data 1:" << data[1] << endl;
cout << passt << endl << accntt << endl;
//cout << "sav:" << savbal << endl << "chek:" << chekbal << endl << "cd:" << cdbal << endl;
return 0;
}
void search(char& accntt, char& passt, string accnt, string pass)
{
string data[3];
ifstream infile;
infile.open("Accnt.txt");
if (infile.fail( ))
{
cout << "File open failed.\n";
exit(1);
}
int linenum=0;
string line;
while (linenum < 2)// || (data[linenum] != accnt)) //while the end of file is NOT reached
{
getline (infile,line); //get one line from the file
data[linenum] = line;
cout << data[linenum] << endl; //and output it
linenum++;
}
infile.close(); //closing the file
if(data[0] == accnt)
{
accntt = 't';
}
else{}
if(data[1] == pass)
{
passt = 't';
}
}
void get_bal(double& savbal, double& chekbal, double& cdbal)
{
ifstream infile;
infile.open("Accnt.txt");
if (infile.fail( ))
{
cout << "File open failed.\n";
exit(1);
}
for(int i=0; i<6; i++)
{
if(i == 2)
{
infile >> savbal;
}
}
cout<<savbal;
infile.close();
cout << "Sucess.\n";
}
Any help would be much appreciated.
thank you in advance