473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

My Program is compiling, but it wont stop running. Can you please help me?

// Program to create new accounts, perform deposits, withdrawals, and bank
//inquiries
#include<iostream>
#include<fstream>
using namespace std;
void menu();
int read_accts(int [], double [], int);
void withdrawal(int [], double [], int);
void deposit(int [], double [], int);
int new_acct(int [], double [], int);
void balance(int [], double[], int);
int main()
{
char answer;
int a, num_elems, max_elems;
int acctnum[6] = {123456,781912,238427,581493,941357,842364};
double balance[6] = {500000,100,65400,500,1000,20};

max_elems = read_accts (acctnum, balance, 100);
num_elems = read_accts (acctnum, balance, 100);

while (num_elems <=6){
read_accts(acctnum, balance, max_elems);
if (answer == 'W') withdrawal(acctnum, balance, num_elems);
if (answer == 'D') deposit(acctnum, balance, num_elems);
}

do {
menu();
cout << "Which banking transaction would you like to use? Enter Q to quit";
cout << " the transaction " << endl;
cin >> answer;

}while ((answer != 'Q') && (answer != 'q'));

system ("pause");
return 0;

}

// Function: read_accts
// Input:
// account numbers and their current balances
// Process:
// reads in the account number and its balance
// Output:
// prints the account number and its balance

//Function to read in the account numbers and their balances
int read_accts (int acctnumarray [], double balancearray [], int maxelems)
{
int a, elemcount = 0;
double balance;
for (a = 0; a <=6; a++){

// declare and open input file
// fstream infile("c:\\Dev-Cpp\\bankproginput.txt");
// ifstream infile(“con”); //un-comment for debugging

cout << "The account number is " << acctnumarray[a];
cout << "and its balance is " << balancearray[a] << endl;

}

return elemcount;


}

// Function: menu
// Input:
// none
// Process:
// creates a menu for the user
// Output:
// A menu is printed

// Function to print the menu
void menu()
{
cout << " Menu of Transactions" << endl;
cout << " W = withdrawal" << endl;
cout << " D = deposit" << endl;
cout << " N = new account" << endl;
cout << " B = balance" << endl;
cout << " Q = quit" << endl;
return;
}

// Function: Withdrawal
// Input:
// none
// Process:
// determines amount of money that the user wants to take out
// Output:
// the amount of money to be withdrawn

// Function to make a withdrawal
void withdrawal (int acctnumarray [], double balancearray [], int numelems)
{
int with = 0;
int acctnum, a;

cout << "Enter your account number: - end with EOF" << endl;
cin >> acctnum;
for (a = 0; a <= numelems; a++);
if (acctnum == acctnumarray[a])
{
cout << "How much money would you like to withdraw?" << endl;
cin >> with;
}
else if (acctnum != acctnumarray[a])
{
cout << "This is an invalid account number." << endl;
}

if (with <= balancearray[a])
{
cout << "Your account does not have a sufficient amounts of funds";
cout << "to proceed with this transaction." << endl;
}

return;
}

// Function: Deposit
// Input:
// none
// Process:
// determines amount of money that the user wants to take out
// Output:
// the amount of money to be withdrawn

//Function to make a deposit
void deposit (int acctnumarray [], double balancearray [], int numelems)
{
int dep = 0;
int acctnum, a;

cout << "Enter your account number:" << endl;
cin >> acctnum;
for (a = 0; a <= numelems; a++);{
cout << "How much money would you like to deposit?" << endl;
cin >> dep;
if (acctnum != acctnumarray[a]);
cout << "This account does not exist." << endl;

}
return;
}

// Function: balance
// Input:
// none
// Process:
// determines amount of money that the user has left in their account
// Output:
// the amount of money to be withdrawn

//Function to tell you how much money is in your account
//void balance (int acctnumarray [], double balancearray [], int numelems)
//{
//}
Nov 29 '06 #1
1 2245
Im not exactly sure if this is what you wanted since im new at this but i got the program to stop being in an endless loop and you can fix up the rest from here.

Here it is:

#include<iostream>
#include<fstream>
using namespace std;
void menu();
int read_accts(int [], double [], int);
void withdrawal(int [], double [], int);
void deposit(int [], double [], int);
int new_acct(int [], double [], int);
void balance(int [], double[], int);
int main()
{
char answer;
int a, num_elems, max_elems;
int acctnum[6] = {123456,781912,238427,581493,941357,842364};
double balance[6] = {500000,100,65400,500,1000,20};

max_elems = read_accts (acctnum, balance, 100);
num_elems = read_accts (acctnum, balance, 100);

do {
menu();
cout << "Which banking transaction would you like to use? Enter Q to quit";
cout << " the transaction " << endl;
cin >> answer;
if (answer == 'W') withdrawal(acctnum, balance, num_elems);
if (answer == 'D') deposit(acctnum, balance, num_elems);

}while ((answer != 'Q') && (answer != 'q'));

system ("pause");
return 0;

}

// Function: read_accts
// Input:
// account numbers and their current balances
// Process:
// reads in the account number and its balance
// Output:
// prints the account number and its balance

//Function to read in the account numbers and their balances
int read_accts (int acctnumarray [], double balancearray [], int maxelems)
{
int a, elemcount = 0;
double balance;
for (a = 0; a <=6; a++){

// declare and open input file
// fstream infile("c:\\Dev-Cpp\\bankproginput.txt");
// ifstream infile(“con”); //un-comment for debugging

cout << "The account number is " << acctnumarray[a];
cout << "and its balance is " << balancearray[a] << endl;

}

return elemcount;


}

// Function: menu
// Input:
// none
// Process:
// creates a menu for the user
// Output:
// A menu is printed

// Function to print the menu
void menu()
{
cout << " Menu of Transactions" << endl;
cout << " W = withdrawal" << endl;
cout << " D = deposit" << endl;
cout << " N = new account" << endl;
cout << " B = balance" << endl;
cout << " Q = quit" << endl;
return;
}

// Function: Withdrawal
// Input:
// none
// Process:
// determines amount of money that the user wants to take out
// Output:
// the amount of money to be withdrawn

// Function to make a withdrawal
void withdrawal (int acctnumarray [], double balancearray [], int numelems)
{
int with = 0;
int acctnum, a;

cout << "Enter your account number: - end with EOF" << endl;
cin >> acctnum;
for (a = 0; a <= numelems; a++);
if (acctnum == acctnumarray[a])
{
cout << "How much money would you like to withdraw?" << endl;
cin >> with;
}
else if (acctnum != acctnumarray[a])
{
cout << "This is an invalid account number." << endl;
}

if (with <= balancearray[a])
{
cout << "Your account does not have a sufficient amounts of funds";
cout << "to proceed with this transaction." << endl;
}

return;
}

// Function: Deposit
// Input:
// none
// Process:
// determines amount of money that the user wants to take out
// Output:
// the amount of money to be withdrawn

//Function to make a deposit
void deposit (int acctnumarray [], double balancearray [], int numelems)
{
int dep = 0;
int acctnum, a;

cout << "Enter your account number:" << endl;
cin >> acctnum;
for (a = 0; a <= numelems; a++);{
cout << "How much money would you like to deposit?" << endl;
cin >> dep;
if (acctnum != acctnumarray[a]);
cout << "This account does not exist." << endl;

}
return;
}

// Function: balance
// Input:
// none
// Process:
// determines amount of money that the user has left in their account
// Output:
// the amount of money to be withdrawn

//Function to tell you how much money is in your account
//void balance (int acctnumarray [], double balancearray [], int numelems)
//{
//}
Nov 30 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Will Stuyvesant | last post by:
I never used the popen or popen2 libraries but it is my understanding that they can capture the output of console based programs. Is it also possible to send keystrokes to console base programs? ...
10
by: An Ony | last post by:
Hi, I made a console program in C# and it works for me. Now I sent it to someone else and he can't run it. Program error or something. His OS is in Swedish. What could this be? Does he have to...
1
by: Mike Hutton | last post by:
I need some help. I am trying to set up our development environment so as to make life easy for my fellow developers (none of whom have used ASP.NET or VS.NET before). We are developing our...
17
by: so many sites so little time | last post by:
all right so the script is pretty simple it goes it retrives what the id of the post is and it lets you edit it well no it doesnt. now if you go to www.kirewire.com/pp2/index/php you will see a...
10
by: ycg0771 | last post by:
I'm trying to modify the following program so that it uses a class to store and retrieve the employee's name, the hourly rate, and the number of hours worked. Use a constructor to initialize the...
6
by: aureao4 | last post by:
I'm new to Java and programming. I'm trying to code a payroll program and continue getting errors. The program worked last week, this week I have to add set, get and a class. I've written the class...
20
by: Boki Digtal | last post by:
Hi All, How to limit the c# program can only run one instance at the same time ? Thank you! Best regards, Boki.
62
by: Ajinkya | last post by:
As "spawnl" executes an exe through C code., similarly how can we compile a C program through another C program (on Windows platform) ?
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.