我是一个初学者,我使用构造函数的概念来编写类似于银行软件的代码,当我执行代码时,它将进入输出屏幕,而当我输入某些内容时,它将返回输入屏幕。我前一段时间已经遇到了这个问题,并且在尝试使用构造函数时,已经在不同的程序中遇到了。感谢您的帮助。
#include<iostream.h>
#include<conio.h>
class account
{
public:
int i, j, count, d, sum;
struct bank
{
int deb[5];
int cre[5];
};
bank b;
account()
{
int deposit();
int credit();
int balance();
}
int deposit()
{
cout << "Enter the amount you want to deposit: ";
i = 0, count;
cin >> b.cre[i];
i++;
d = totaldep();
cout << "Total deposit is: " << d;
return 0;
}
int credit()
{
cout << "Enter the amout you want to take: ";
j = 0;
cin >> b.deb[j];
j++;
balance();
return 0;
}
int balance()
{
cout << "The balance is " << d - b.deb[j];
return 0;
}
int totaldep()
{
for (count = 0; count <= i; count++)
{
sum = sum + b.cre[count];
}
return sum;
}
};
void main()
{
account a;
clrscr();
getch();
}
因此,正如我所看到的,您正在编写函数声明,但是实际上您需要调用它们。只是不要在函数调用之前编写返回类型。