C ++银行系统项目问题 [英] C++ bank system project problem

查看:66
本文介绍了C ++银行系统项目问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们我正在开发一个银行系统项目,而且每件事都运作良好

除非我尝试打印我输入的值,我会得到奇怪的字符串和随机数字,这里是代码:

  #include   <   iostream  >  
使用 命名空间标准;

struct 地址{
char stName [ 10 ];
int houseNum;
};

struct 帐户{
char name [ 10 ];
int accnumber;
double 余额;
地址地址;
};
// -------------------- -------------------------------------------------- --------------------------- //
void getData(帐户account [], int size, int * counter);


// ------------ -------------------------------------------------- ---------------------------------- //
int main(){
int choice;
int i = 0 ;
int size = 10 ;
账户a [size];
while true ){

cout<< \t\t\t ---输入你的选择---< < ENDL;
cout<< ENDL;
cout<< \t\t\t 1 - 创建帐户\ n;
cout<< ENDL;
cout<< \t\t\t 2 - 存款<< endl;
cout<< ENDL;
cout<< \t\t\t 3 - 提取资金<< endl;
cout<< ENDL;
cout<< \t\t\t 4 - 显示<< ENDL;
cout<< ENDL;
cout<< \t\t\t 5 - 退出<< ENDL;
cout<< ENDL;
cout<< \t\t\t选项是:;
cin>>选择;
if (choice == 1
getData(a,size,& ;一世);

// printnig value - >只需检查
cout<< endl<< ENDL;
cout<< 名称:<< a [i] .name<< ENDL;
cout<< 帐号:<< a [i] .accnumber<< ENDL;
cout<< 余额:<< a [i] .balance<< ENDL;
cout<< House num:<< a [i] .addr.houseNum<<结束
cout<< 街道名称:<< a [i] .addr.stName<< ENDL;

}

}

void getData(账户账户[], int size, int * counter){
int i = * counter;

cout<< 名称:;
cin>>帐户[I]。名称;

cout<< acc number:;
cin>>帐户[I] .accnumber;
cout<< balance:;
cin>>帐户[I] .balance;
cout<< 地址信息<< ENDL;
cout<< 门牌号:;
cin>>帐户[I] .addr.houseNum;
cout<< 街道名称:;
cin>> accounts [i] .addr.stName;
i ++;
* counter = i;
cout<< ENDL;
cout<< 完成....<< ENDL;
system( pause);
}





我的尝试:



i没有任何线索,是什么导致它表现得那样!!

解决方案

你的问题是 i ++ ...您将值存储在 i 的位置,但会增加它并在位置 i ++ ...

hey guys i'm working on a bank system project and every thing is working well
except when i try to print the values i entered i get wierd strings and random numbers ,, here's the code :

#include <iostream>
using namespace std;

struct Address{
	char stName[10];
	int houseNum;
};

struct Account{
	char name[10];
	int accnumber;
	double balance;
	Address addr;
};
// ------------------------------------------------------------------------------------------------- //
void getData( Account accounts[], int size , int *counter);


// ------------------------------------------------------------------------------------------------ //
int main(){
int choice;
int i = 0;
int size = 10;
Account a[size];
while (true){

	cout << "\t\t\t --- Enter your choise --- " << endl;
	cout << endl;
	cout << "\t\t\t 1 - Create Account\n";
	cout << endl;
	cout <<"\t\t\t 2 - Deposit Money" <<endl;
	cout << endl;
	cout << "\t\t\t 3 - Withdraw Money" <<endl;
	cout << endl;
	cout << "\t\t\t 4 - Display" << endl;
	cout << endl;
	cout << "\t\t\t 5 - Exit" << endl;
	cout << endl;
	cout << "\t\t\t choice is :  ";
	cin >> choice;
	if (choice == 1)
	getData(a , size ,&i);
	
	// printnig the value -> just checking
	cout << endl << endl;
	cout << "Name: " << a[i].name << endl;
	cout << "Account number : " << a[i].accnumber << endl;
	cout << "Balance: " << a[i].balance << endl;
	cout << "House num: " << a[i].addr.houseNum << endl ;
	cout << "Street name: " << a[i].addr.stName << endl;
	
}
	
}

void getData(Account accounts[], int size,int *counter ){
	int i = *counter;
	
	cout << "Name: ";
	cin >> accounts[i].name;
	
	cout << "acc number : " ;
	cin >> accounts[i].accnumber;
	cout << "balance : " ;
	cin >> accounts[i].balance;
	cout << "Address info " << endl;
	cout << "House number : " ;
	cin >> accounts[i].addr.houseNum;
	cout << "Street name : ";
	cin >> accounts[i].addr.stName ;
	i++;
	*counter = i;
	cout << endl;
	cout << "Done ...." << endl;
	system("pause");
}



What I have tried:

i have no clue ,, what is causing it to behave like that !!

解决方案

Your problem is i++... You are storing the values at position i, but increments it and prints the values at position i++...


这篇关于C ++银行系统项目问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆