【发布时间】:2014-03-10 16:07:23
【问题描述】:
我正在制作一个简单的银行帐户处理系统,并将帐户信息保存为一个数组,但是在传递帐户信息时遇到了困难,我正在将数组从文本文件读取到程序中,但这需要从读取文件的函数传递到处理提款、存款和查看余额的函数,传递的数组旨在存储当前余额,作为透支的布尔值的替代品以及最近 3 次取款和存款。
withdraw 函数的样子
float Withdraw() //function handled withdraw requests
{
//variables
const int M = 3; //declare const int for withdraws
const int N = 8; //declare const int for account
float withdrawAmount = 0.0f; //used for internam laths in function
float currentBalance = 0.0f; //used internally in function
float newBalance = 0.0f; //passed to write function
float withdraws[M]; //passed to write function
float account[N]; //passed and returned from read function
//call readFile function
readFile(account[N]);
cout << account[0];
//user interface
cout << "Withdraw opnened" << endl; //prompts user for input of a withdraw amount and displays current balance
cout << "Your Current Balance is: " << currentBalance << endl;
cout << "How Much Would You Like to Withdraw?" << endl;
cin >> withdrawAmount;
newBalance = currentBalance - withdrawAmount; //calculates balance after withdraw
withdraws[2] = withdraws[1];
withdraws[1] = withdraws[0];
withdraws[0] = withdrawAmount;
system("PAUSE");
system("cls");
writeFile(newBalance, withdraws[M]);
Menu();
return 0;
}
读取文件的函数看起来像
float readFile(float account[8])
{
//variables
const int N = 8;
float accountRead[N];
//read file
ifstream file("floats.txt");
if (!file.is_open())
{
cerr << "Error opening file" << endl;
return 0;
}
for (int i = 0; i < N && file >> accountRead[i]; ++i)
;
if (file)
{
}
account = accountRead;
return account[N];
}
任何指导都将不胜感激,因为我花了几个小时试图研究这个但无处可去
【问题讨论】:
-
'我已经花了好几个小时试图研究这个'这听起来很荒谬!只需查看相关部分下的右侧。
-
@πάνταῥεῖ 别管他 ;)
标签: c++ arrays parameters