Функция C++ не работает
Эй ребята я строю проект на c++ это в основном банковская система
две функции моего кода не работают, я не знаю почему!!
функции вывод и отображение,,
вот код
#include<iostream> using namespace std; struct Address{ string stName; int houseNum; }; struct Account{ string name; int accnumber; double balance; Address addr; }; void menu(); // program interface void withdraw(Account accounts[] , int acnum , double amount); void Create_account(int &i,Account accounts[] , Address addreses[]); void display(Account accounts[] , Address addreses[] , int acnum); double deposit(double&balance , double amount); int main(){ while (true){ system("color 0a"); menu(); } } // main Menu , program start void menu(){ // index of array int i = 0 ; int choice; Account accounts[10] ; Address addreses[10]; int acnum; double amount; cout << endl; system("cls"); 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; system("cls"); switch (choice){ case 1: Create_account(i, accounts , addreses); break; case 2: cout << "\t\tEnter the amount you Want to deposit :" ; break; case 3 : cout << "\t\tPlease enter the acc number: " ; cin >> acnum; cout << "\t\tEnter amount to withdraw : "; cin >> amount; withdraw(accounts , acnum , amount); break; case 4: cout << "\t\tPlease enter the acc number: " ; cin >> acnum; display(accounts , addreses , acnum); break; break; case 5: cout << "Good bye !!!"; exit(0); break; } } // function to Create a new account void Create_account(int &i , Account accounts[] , Address addreses[]){ system("cls"); cout << "\t\t\t --- Create New Account --- " << endl; cout << "\t\t Name: "; cin >> accounts[i].name; cout << "\t\t Account Number: "; cin >> accounts[i].accnumber; cout << "\t\t Balance: "; cin >> accounts[i].balance; cout << "\t\t\t --- Address Information --- " << endl; cout << "\t\t Streat Name: "; cin >> addreses[i].stName; cout << "\t\t House Number : "; cin >> addreses[i].houseNum; i++; } void withdraw(Account accounts[] , int acnum , double amount){ for (int i = 0; i <= 10 ;i++){ if (accounts[i].accnumber == acnum){ accounts[i].balance -= amount; cout << "\t\tDone."; break; } else if (i == 10 ){ cout << "\t\tAccount Not Found !!!" << endl; } }} double deposit(double &balance , double amount){ } void display(Account accounts[] , Address addreses[] , int acnum){ for (int i = 0; i <= 10 ;i++){ if (accounts[i].accnumber == acnum){ cout << "\t\tName : " << accounts[i].name; system("PAUSE"); } }}
Что я уже пробовал:
каждая вещь и это убивает меня ):
Richard MacCutchan
Ваша первая ошибка-использование double
типы для хранения финансовых ценностей. Вы должны использовать int
или decimal
для поддержания точности.