The program below in C will build and pass the Pass without debugging. I am trying to pass the variables by values or address. When I get to the 3rd item on the menu it doesn’t pass the account balance from the results of line 2 of the main menu.
The menus suppose to read as follows:
When I select menu item 2 after running the code the menu should display:
Process a case deposit
The current Savings Account Balance is: $93.00
Enter the amount of Deposit $100
The new balance is $193.00
Press any key to continue
Select menu Item 3,
the current balance is displayed and the withdrawal is subtracted from it. The screen should print:
Process a cash withdrawal.
The current Savings Account Balance is: $193.00
Enter the amount to be withdrawn $100
The new balance is: $93.00
Press any key to continue
Menu 5, Provides Account Balances
The current Savings Account Balance is: $93.00
The current Checking Account Balance is: $0.00
P ress any key to continue
I am trying to pass the variable balance to the next screen.
This is my program:
#include
#include
#include
#include
#include
#include
int program();
char exit();
void number1();
int number2();
int number3(int); //make change in prototype
int number4();
void number5(int); //make change in prototype
void number6();
void contProgram();
int mainBalance = 0; //This will hold loaded accounts balance
int main()
{
char stay = ‘ ‘;
do
{
system(“cls”);
program();
printf(“nn”);
printf(“Would you like to make another transaction?”);
printf(“Y/N: n”);
getchar();
if (stay == ‘y’ && stay == ‘Y’)
{
system(“cls”);
}
if (stay == ‘n’ && stay == ‘n’)
{
system(“cls”);
}
} while (stay != ‘n’ && stay != ‘N’);
return 0;
}
int program()
{
int selection1;
printf(“1. Create New Account n”);
printf(“2. Cash Deposit n”);
printf(“3. Cash Withdrawal n”);
printf(“4. Fund Transfer n”);
printf(“5. Account Information n”);
printf(“6. Transaction Information n”);
printf(“7. Exit n”);
printf(“Press a choice between the range of [1-7]: “);
scanf_s(“%d”, &selection1);
printf(“nn”);
system(“cls”);
switch (selection1)
{
case 1:
printf(“1. Here is where you would add an account nn”);
number1();
break;
case 2:
printf(“2. Here is where you deposit money nn”);
mainBalance = number2();
break;
case 3:
printf(“3. Here is where you withdraw funds nn”);
mainBalance = number3(mainBalance);
break;
case 4:
printf(“4. Here is where you transfer funds nn”);
number4();
break;
case 5:
printf(“5. This is your account information nn”);
number5(mainBalance);
break;
case 6:
printf(“6. This is your transaction information nn”);
number6();
break;
case 7:
printf(“7. You have selected to exit? nn”);
break;
default:
break;
}
if (selection1>7 || selection1 == 0)
{
printf(“Your input is out of range! Enter a choice between 1 to 7!n”);
contProgram();
}
return selection1;
}
char exit()
{
system(“cls”);
char exitProgram;
exitProgram = ‘Y’;
contProgram();
return exitProgram;
}
void number1()
{
system(“cls”);
printf(“Adding new accounts is not possible at this time:nn”);
contProgram();
}
int number2()
{
system(“cls”);
int x = 0;
int y = 0;
int z = 0;
printf(“Enter the current account balance: “);
scanf_s(“%d”, &x);
printf(“nn”);
printf(“Enter the amount to deposit: “);
scanf_s(“%d”, &y);
printf(“nn”);
z = x + y;
printf(“The new balance is: $ %dnn”, z);
contProgram();
return z;
}
int number3(int mb) //Accept main Balance as parameter here
{
system(“cls”);
int a2 = mb;
int b2 = 0;
int c2 = 0;
printf(“Current Saving account balance: %d”, a2);
printf(“nn”);
tryagain:
printf(“Enter the amount to withdraw: “);
scanf_s(“%d”, &b2);
if (b2>a2)
{
printf(“Amount exceeds than balance!”);
goto tryagain;
}
printf(“nn”);
c2 = a2 – b2;
printf(“The new balance is: $ %dnn”, c2);
contProgram();
return c2;
}
int number4()
{
system(“cls”);
int a3 = 0; //checking
int b3 = 0; //savings
int c3 = 0; //transfer
int d3 = 0; //new checking
int e3 = 0; //new savings
printf(“Enter the current checking account balance: “);
scanf_s(“%d”, &a3);
printf(“nn”);
printf(“Enter the current savings account balance: “);
scanf_s(“%d”, &b3);
printf(“nn”);
printf(“Enter the amount to be transferred: “);
scanf_s(“%d”, &c3);
printf(“nn”);
d3 = a3 – b3;
printf(“The new checking account balance is: $ %d”, d3);
printf(“nn”);
e3 = b3 + c3;
printf(“The new savings account balance is: $ %d”, e3);
printf(“nn”);
contProgram();
return c3;
}
void number5(int mb)// Accept Main Balance
{
int a3 = 0; //checking
int b3 = mb; //savings
system(“cls”);
printf(“The Current Saving Balance is: %d nn”, b3);
printf(“The Current Checking Balance is: %d nn”, a3);
contProgram();
}
void number6()
{
system(“cls”);
printf(“There is no transaction history available at this time!nn”);
contProgram();
}
void contProgram()
{
printf(“nt Press any key to continue…n”);
_getch(); //captures a character (any character)
system(“cls”); //clears the screen
}
Expert Answer
If the balance need to be forwarded to next console then you need to have database connectivity with the program.
Use header #include<SQLAPI.h>
under main function put the below codes
——————————————-
SAConnection con;
try
{
// connect to database
// in this example, it is Oracle,
// but can also be Sybase, Informix, DB2
// SQLServer, InterBase, SQLBase and ODBC
con.Connect (“test”, // database name
“tester”, // user name
“tester”, // password
SA_Oracle_Client); //Oracle Client
printf(“We are connected!n”);
// Disconnect is optional
// autodisconnect will occur in destructor if needed
con.Disconnect();
printf(“We are disconnected!n”);
}
—————————————————————
Other than this the rectified program is below ::
—————————————————————-
#include
#include
#include
int program();
char exit();
void number1();
int number2(int);
int number3(int); //make change in prototype
int number4(int, int);
void number5(int); //make change in prototype
void number6();
void contProgram();
int mainBalance = 0; //This will hold loaded saving accounts balance
int mainBalanceC = 0; //This will hold loaded current accounts balance
int main()
{
char stay = ‘ ‘; int fund=0;
do
{
system(“cls”);
program();
printf(“nn”);
printf(“Would you like to make another transaction?”);
printf(“Y/N: n”);
getchar();
if (stay == ‘y’ && stay == ‘Y’)
{
system(“cls”);
}
if (stay == ‘n’ && stay == ‘n’)
{
system(“cls”);
}
} while (stay != ‘n’ && stay != ‘N’);
return 0;
}
int program()
{
int selection1;
printf(“1. Create New Account n”);
printf(“2. Cash Deposit n”);
printf(“3. Cash Withdrawal n”);
printf(“4. Fund Transfer n”);
printf(“5. Account Information n”);
printf(“6. Transaction Information n”);
printf(“7. Exit n”);
printf(“Press a choice between the range of [1-7]: “);
scanf(“%d”, &selection1);
printf(“nn”);
system(“cls”);
switch (selection1)
{
case 1:
printf(“1. Here is where you would add an account nn”);
number1();
break;
case 2:
printf(“2. Here is where you deposit money nn”);
mainBalance = number2(mainBalance);
break;
case 3:
printf(“3. Here is where you withdraw funds nn”);
mainBalance = number3(mainBalance);
break;
case 4:
printf(“4. Here is where you transfer funds nn”);
fund=number4(mainBalance, mainBalance);
mainBalance+=fund;
printf(“The new savings account balance is: $ %d”, mainBalance);
mainBalanceC-=fund;
printf(“The new current account balance is: $ %d”, mainBalance);
break;
case 5:
printf(“5. This is your account information nn”);
number5(mainBalance);
break;
case 6:
printf(“6. This is your transaction information nn”);
number6();
break;
case 7:
printf(“7. You have selected to exit? nn”);
break;
default:
break;
}
if (selection1>7 || selection1 == 0)
{
printf(“Your input is out of range! Enter a choice between 1 to 7!n”);
contProgram();
}
return selection1;
}
char exit()
{
system(“cls”);
char exitProgram;
exitProgram = ‘Y’;
contProgram();
return exitProgram;
}
void number1()
{
system(“cls”);
printf(“Adding new accounts is not possible at this time:nn”);
contProgram();
}
int number2(int mbal)
{
system(“cls”);
int x = mbal;
int y = 0;
int z = 0;
if(x == 0) //it suggests the account balance is empty or NEW
{
printf(“Enter the current account balance: “);
scanf(“%d”, &x);
}
else
printf(“The current account balance is: %d”,x);
printf(“nn”);
printf(“Enter the amount to deposit: “);
scanf(“%d”, &y);
printf(“nn”);
z = x + y;
printf(“The new balance is: $ %dnn”, z);
contProgram();
return z;
}
int number3(int mb) //Accept main Balance as parameter here
{
system(“cls”);
int a2 = mb;
int b2 = 0;
int c2 = 0;
printf(“Current Saving account balance: %d”, a2);
printf(“nn”);
tryagain:
printf(“Enter the amount to withdraw: “);
scanf(“%d”, &b2);
if (b2>a2)
{
printf(“Amount exceeds than balance! n”);
goto tryagain;
}
printf(“nn”);
c2 = a2 – b2;
printf(“The new balance is: $ %dnn”, c2);
contProgram();
return c2;
}
int number4(int mbs, int mbc)
{
system(“cls”);
int a3 = mbc; //checking
int b3 = mbs; //savings
int c3 = 0; //transfer
// int d3 = 0; //new checking
//int e3 = 0; //new savings
if(b3 == 0) //it suggests the savings account balance is empty or NEW
{
printf(“Enter the current savings account balance: “);
scanf(“%d”, &b3);
}
else
printf(“The current savings account balance: is: %d”,b3);
if(a3 == 0) //it suggests the current account balance is empty or NEW
{
printf(“Enter the current checking account balance: “);
scanf(“%d”, &a3);
}
else
printf(“The current checking account balance: is: %d”,a3);
tryagain1:
printf(“nn”);
printf(“Enter the amount to be transferred: “);
scanf(“%d”, &c3);
printf(“nn”);
if (c3>a3)
{
printf(“Amount exceeds than balance! n”);
goto tryagain1;
}
contProgram();
return c3;
}
void number5(int mb)// Accept Main Balance
{
int a3 = 0; //checking
int b3 = mb; //savings
system(“cls”);
printf(“The Current Saving Balance is: %d nn”, b3);
printf(“The Current Checking Balance is: %d nn”, a3);
contProgram();
}
void number6()
{
system(“cls”);
printf(“There is no transaction history available at this time!nn”);
contProgram();
}
void contProgram()
{
printf(“nt Press any key to continue…n”);
getch(); //captures a character (any character)
system(“cls”); //clears the screen
}