ok I am very new to C++. This is like the 2nd time I am writing a program. I need to write a simple banking program that you can deposit withdraw and see your balance and stuff.Also there is a data file called bank.dat and I need to use it to get account numbers and balances.Am I on the right track?And if not can you help me pls?And why does it exits the program when i type the transaction code?Thanks for the help
Do you want to read data from bank.dat file? Is it a text file or binary?
In your 21th line you didn't put any value to the variables.
In your 26th line the << operator is used incorrectly. The cin can be used for only reading by >> operator.
In your switch statement the name of the variables (for example: in 42th line) aren't instructions and don't do anything.
Line 15 you are opening a file but not doing anything with that, so do something like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
fin.open("Bank.dat");
// check whether it is open
if(!fin.is_open())
return 1; // not opened so we can't proceed further
// it is opened so what do you want to do with it
// read the buffer and store it in your variables
while(fin.good())
{
fin >> account_number;
fin >> balance;
// make sure yourself(or debug)
cout << account_number << ":" << balance << endl;
}
// then rest of your code
screw I dont know wat do you mean by I didn't put any variables and are you saying that i should delete line 42
And I know I still have alot of errors can you guys help me without telling me the code
thanks for both your help
while(fin.good())
{
fin >> account_number;
fin >> balance;
// make sure yourself(or debug)
cout << account_number << ":" << balance << endl;
}
This code fragment you read data but only last two data (account_number and balance) is preserved, the previous data isn't stored. So the previous balanced were droped.
You didn't put any initialization to total_deposit and total_withdrawals;
Before you want to use a variable you should put a value. At least zero value.
I could repeat ZHuge question: what/where are the errors?
I don't like standard C commands like sscanf(hold, "%d %d %f %f", &ACCOUNT_NUMBER, &CODE, &AMOUNT, &BALANCE); to mix with C++.
I would use the
1 2 3 4
fin >> ACCOUNT_NUMBER;
fin >> CODE;
fin >> AMOUNT;
fin >> BALANCE;
OMG im so stupid how did i forget that thank you screw
and screw when i change sscanf to fin it tells me that its overloaded
I just have one more question after i run the program it gives me debugging error