Hi. I'm working on a program for a class that requires me to make a checking account simulator. However, every time I try to compile it, I get errors. I have gotten it down to very minimal errors, but the ones I do still have I cannot seem to fix.
Here is my code: - #include <stdio.h>
-
#define WITHDRAW 1
-
#define DEPOSIT 2
-
#define SUMMARY 3
-
#define QUIT 4
-
-
void print_greeting (void);
-
int print_menu (void);
-
float get_positive_value (void);
-
float withdrawal (float balance, float withdrawal_amt);
-
float deposit (float balance, float deposit_amt);
-
void print_receipt (int total_withdrawals, int total_deposits, float beg_balanc\
-
e, float balance);
-
-
int main()
-
{
-
float beg_balance;
-
float balance;
-
float withdrawal_amt;
-
float deposit_amt;
-
int total_withdrawals;
-
int total_deposits;
-
int selection;
-
-
print_greeting();
-
beg_balance = get_positive_value();
-
balance = beg_balance;
-
printf("Your starting balance is %f.", beg_balance);
-
print_menu ();
-
-
while(selection != 4)
-
{
-
selection = print_menu();
-
switch(selection){
-
case 1: balance = withdrawal(balance, withdrawal_amt);
-
total_withdrawals++;
-
case 2: balance = deposit(balance, deposit_amt);
-
total_deposits++;
-
case 3: print_receipt(total_withdrawals, total_deposits, balance, b\
-
eg_balance);
-
default: printf("Error. Invalid Input.");
-
}
-
if(balance < 0)
-
{
-
printf("WARNING! Your balance has gone below zero! I don't know how yo\
-
u pulled that off, but I suggest you put some money back in!");
-
}
-
return 0;
-
}
-
}
-
-
void print_greeting (void)
-
{
-
printf("Welcome to the Super Awesome Checking Account Simulator! This progr\
-
am will simulate withdrawing and depositing money into a bank account.\n");
-
printf("There are three main functions to this program. After entering your\
-
initial balance, you have the option to either make a withdrawal, make a depos\
-
it, or view an account summary. The program will also keep track of the number \
-
of times you have withdrawn or deposited money.\n");
-
printf("So what are you waiting for? Let's begin with a starting amount of \
-
money! \n");
-
}
-
-
float get_positive_value (void)
-
{
-
float money;
-
scanf("%f", &money);
-
if(money <= 0)
-
{
-
printf("You can't use that amount. What are you, some kind of wizard?\n\
-
");
-
printf("Enter a valid amount. ");
-
scanf("%f", &money);
-
}
-
if(money > 0)
-
}
-
-
int print_menu (void)
-
{
-
int selection;
-
printf("1) Withdraw\n2) Deposit\n3) Summary\n4)Quit\n");
-
printf("Select an option. ");
-
scanf("%d", &selection);
-
-
return selection;
-
}
-
-
float withdrawal (float balance, float withdrawal_amt)
-
{
-
printf("Enter amount to withdraw. ");
-
scanf("%f", &withdrawal_amt);
-
if(withdrawal_amt <= 0)
-
{
-
printf("You can't use that amount. What are you, some kind of wizard?\n\
-
");
-
printf("Enter a valid amount. ");
-
}
-
if(withdrawal_amt > 0)
-
{
-
balance = balance - withdrawal_amt;
-
}
-
-
return balance;
-
}
-
-
float deposit (float balance, float deposit_amt)
-
{
-
printf("Enter amount to deposit. ");
-
scanf("%f", &deposit_amt);
-
if(deposit_amt <= 0)
-
{
-
printf("You can't use that amount. What are you, some kind of wizard?\n\
-
");
-
printf("Enter a valid amount. ");
-
}
-
if(deposit_amt > 0)
-
{
-
balance = balance - deposit_amt;
-
}
-
-
return balance;
-
}
-
-
void print_receipt (int total_withdrawals, int total_deposits, float beg_balanc\
-
e, float balance)
-
{
-
printf("----------------------------------------------------\n");
-
printf(" Account Summary\n");
-
printf("\n");
-
printf("Beginning balance: %f \n", &beg_balance);
-
printf("Current balance: %f \n", &balance);
-
printf("\n");
-
printf("\n");
-
printf("Total withdrawals: %d \n", &total_withdrawals);
-
printf("Total deposits: %d \n", &total_deposits);
-
printf("----------------------------------------------------\n");
-
}
The errors I am currently getting are: - proj2.c: In function âget_positive_valueâ:
-
proj2.c:77: error: expected expression before â}â token
-
proj2.c: In function âprint_receiptâ:
-
proj2.c:128: warning: format â%fâ expects type âdoubleâ, but argument 2 has type âfloat *â
-
proj2.c:129: warning: format â%fâ expects type âdoubleâ, but argument 2 has type âfloat *â
-
proj2.c:132: warning: format â%dâ expects type âintâ, but argument 2 has type âint *â
-
proj2.c:133: warning: format â%dâ expects type âintâ, but argument 2 has type âint *â
-
Every time I go to the functions the errors are mentioning and try to tweak something, either the error remains, more errors are made, or both.
Is there anything I can do?
EDIT: I've fixed both of these issues by removing the ampersands in print_receipt and removing the if statement in line 75. But now I am getting these errors: - proj2.c: In function âget_positive_valueâ:
-
proj2.c:76: warning: control reaches end of non-void function
-
proj2.c: In function âmainâ:
-
proj2.c:57: warning: control reaches end of non-void function
-
proj2.c:40: warning: âselectionâ is used uninitialized in this function
-
proj2.c:44: warning: âwithdrawal_amtâ may be used uninitialized in this function
-
proj2.c:45: warning: âtotal_withdrawalsâ may be used uninitialized in this function
-
proj2.c:46: warning: âdeposit_amtâ may be used uninitialized in this function
-
proj2.c:47: warning: âtotal_depositsâ may be used uninitialized in this function
Any help?
4 16124
On line 75, you start an if statement. Then you just end. You don't say what to do after the if.
For the rest, take out the ampersands (&). An ampersand before a variable returns the address of the variable.
Thank you so much for this. I'm relatively new to programming so I had no idea what to do.
I fixed those errors, but now have more: - proj2.c: In function âget_positive_valueâ:
-
proj2.c:76: warning: control reaches end of non-void function
-
proj2.c: In function âmainâ:
-
proj2.c:57: warning: control reaches end of non-void function
-
proj2.c:40: warning: âselectionâ is used uninitialized in this function
-
proj2.c:44: warning: âwithdrawal_amtâ may be used uninitialized in this function
-
proj2.c:45: warning: âtotal_withdrawalsâ may be used uninitialized in this function
-
proj2.c:46: warning: âdeposit_amtâ may be used uninitialized in this function
-
proj2.c:47: warning: âtotal_depositsâ may be used uninitialized in this function
:/
I would have to see your newly modified code to give definitive answers but in general, the non-void function warning means that it got to the end and you didn't return any value for the function when it's expecting a value to be returned. The other warning means that the variable may not have a value set. When you declare a variable, you should also set it to some default value so you always know what the value is, if you don't, it will be some random value.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Lawrence Spector |
last post by:
I ran into a problem using g++. Visual Studio 2005 never complained
about this, but with g++ I ran into this error. I can't figure out if
I've done something wrong or if this is a compiler bug. ...
|
by: sanctus |
last post by:
Is there a typical mistake which generates the error:
" error: expected primary-expression before ‘)’ token"
because I fail to see why I get this problem and the code is too big to post it here....
|
by: Ram Prasad |
last post by:
I am trying to write a simple libspf2 plugin code for my postfix
( milter)
I am getting this unhelpful error message when I try to compile
gcc -g1 -Wall -I/usr/local/include/spf2 -I. -c mfunc.c...
|
by: gyre |
last post by:
Hi!
I've got a little problem I've been dealing with for several days :((
Code is written in Qt.
I'll try to explain it:
I created an abstract class "VcaNode" with 4 virtual methods and 3 other...
|
by: amitmool |
last post by:
hi, i have used the queue library file and try to use the template as
template <class QueueItem>
queue <QueueItem>::~queue() // line 25
{
}
template <class QueueItem>
void...
|
by: opcs |
last post by:
here is my complete code, can any one help me why does this error occurs and how to resolve it.
also, error is at the line "list.hdr =(list *) malloc(sizeof(struct SkipList));" is the size...
|
by: lordhoban |
last post by:
My program was running fine under visual studio, but I moved it over to Linux, and have run into one problem I have no idea how to fix.
error: expected expression before 'int'
(all the...
|
by: sam23 |
last post by:
Hi all, im new to this programming language and i tried to use my Xcode to build and run this code but i got a error :(, and another error is
i need a help guys
#include <GLUT/glut.h>...
|
by: JEFFREY MUSGRAY |
last post by:
I have received alot of help from this site and I am grateful. My problem is that I was able to get the first part of code to work. I tested it via the immediate window. I received the compile error...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |