473,387 Members | 3,801 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,387 software developers and data experts.

error: expected expression before '}' token

3
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:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #define WITHDRAW 1
  3. #define DEPOSIT 2
  4. #define SUMMARY 3
  5. #define QUIT 4
  6.  
  7. void print_greeting (void);
  8. int print_menu (void);
  9. float get_positive_value (void);
  10. float withdrawal (float balance, float withdrawal_amt);
  11. float deposit (float balance, float deposit_amt);
  12. void print_receipt (int total_withdrawals, int total_deposits, float beg_balanc\
  13. e, float balance);
  14.  
  15. int main()
  16. {
  17.     float beg_balance;
  18.     float balance;
  19.     float withdrawal_amt;
  20.     float deposit_amt;
  21.     int total_withdrawals;
  22.     int total_deposits;
  23.     int selection;
  24.  
  25.     print_greeting();
  26.     beg_balance = get_positive_value();
  27.     balance = beg_balance;
  28.     printf("Your starting balance is %f.", beg_balance);
  29.     print_menu ();
  30.  
  31.     while(selection != 4)
  32.     {
  33.         selection = print_menu();
  34.         switch(selection){
  35.             case 1: balance = withdrawal(balance, withdrawal_amt);
  36.                     total_withdrawals++;
  37.             case 2: balance = deposit(balance, deposit_amt);
  38.                     total_deposits++;
  39.             case 3: print_receipt(total_withdrawals, total_deposits, balance, b\
  40. eg_balance);
  41.             default: printf("Error. Invalid Input.");
  42.         }
  43.     if(balance < 0)
  44.     {
  45.          printf("WARNING! Your balance has gone below zero! I don't know how yo\
  46. u pulled that off, but I suggest you put some money back in!");
  47.     }
  48.     return 0;
  49.     }
  50. }
  51.  
  52. void print_greeting (void)
  53. {
  54.     printf("Welcome to the Super Awesome Checking Account Simulator! This progr\
  55. am will simulate withdrawing and depositing money into a bank account.\n");
  56.     printf("There are three main functions to this program. After entering your\
  57.  initial balance, you have the option to either make a withdrawal, make a depos\
  58. it, or view an account summary. The program will also keep track of the number \
  59. of times you have withdrawn or deposited money.\n");
  60.     printf("So what are you waiting for? Let's begin with a starting amount of \
  61. money! \n");
  62. }
  63.  
  64. float get_positive_value (void)
  65. {
  66.     float money;
  67.     scanf("%f", &money);
  68.     if(money <= 0)
  69.     {
  70.         printf("You can't use that amount. What are you, some kind of wizard?\n\
  71. ");
  72.         printf("Enter a valid amount. ");
  73.         scanf("%f", &money);
  74.     }
  75.     if(money > 0)
  76. }
  77.  
  78. int print_menu (void)
  79. {
  80.     int selection;
  81.     printf("1) Withdraw\n2) Deposit\n3) Summary\n4)Quit\n");
  82.     printf("Select an option. ");
  83.     scanf("%d", &selection);
  84.  
  85.     return selection;
  86. }
  87.  
  88. float withdrawal (float balance, float withdrawal_amt)
  89. {
  90.     printf("Enter amount to withdraw. ");
  91.     scanf("%f", &withdrawal_amt);
  92.     if(withdrawal_amt <= 0)
  93.     {
  94.         printf("You can't use that amount. What are you, some kind of wizard?\n\
  95. ");
  96.         printf("Enter a valid amount. ");
  97.     }
  98.     if(withdrawal_amt > 0)
  99.     {
  100.         balance = balance - withdrawal_amt;
  101.     }
  102.  
  103.     return balance;
  104. }
  105.  
  106. float deposit (float balance, float deposit_amt)
  107. {
  108.     printf("Enter amount to deposit. ");
  109.     scanf("%f", &deposit_amt);
  110.     if(deposit_amt <= 0)
  111.     {
  112.         printf("You can't use that amount. What are you, some kind of wizard?\n\
  113. ");
  114.         printf("Enter a valid amount. ");
  115.     }
  116.     if(deposit_amt > 0)
  117.     {
  118.         balance = balance - deposit_amt;
  119.     }
  120.  
  121.     return balance;
  122. }
  123.  
  124. void print_receipt (int total_withdrawals, int total_deposits, float beg_balanc\
  125. e, float balance)
  126. {
  127.     printf("----------------------------------------------------\n");
  128.     printf("                  Account Summary\n");
  129.     printf("\n");
  130.     printf("Beginning balance: %f \n", &beg_balance);
  131.     printf("Current balance:   %f \n", &balance);
  132.     printf("\n");
  133.     printf("\n");
  134.     printf("Total withdrawals: %d \n", &total_withdrawals);
  135.     printf("Total deposits:    %d \n", &total_deposits);
  136.     printf("----------------------------------------------------\n");
  137. }
The errors I am currently getting are:

Expand|Select|Wrap|Line Numbers
  1. proj2.c: In function âget_positive_valueâ:
  2. proj2.c:77: error: expected expression before â}â token
  3. proj2.c: In function âprint_receiptâ:
  4. proj2.c:128: warning: format â%fâ expects type âdoubleâ, but argument 2 has type âfloat *â
  5. proj2.c:129: warning: format â%fâ expects type âdoubleâ, but argument 2 has type âfloat *â
  6. proj2.c:132: warning: format â%dâ expects type âintâ, but argument 2 has type âint *â
  7. proj2.c:133: warning: format â%dâ expects type âintâ, but argument 2 has type âint *â
  8.  
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:

Expand|Select|Wrap|Line Numbers
  1. proj2.c: In function âget_positive_valueâ:
  2. proj2.c:76: warning: control reaches end of non-void function
  3. proj2.c: In function âmainâ:
  4. proj2.c:57: warning: control reaches end of non-void function
  5. proj2.c:40: warning: âselectionâ is used uninitialized in this function
  6. proj2.c:44: warning: âwithdrawal_amtâ may be used uninitialized in this function
  7. proj2.c:45: warning: âtotal_withdrawalsâ may be used uninitialized in this function
  8. proj2.c:46: warning: âdeposit_amtâ may be used uninitialized in this function
  9. proj2.c:47: warning: âtotal_depositsâ may be used uninitialized in this function
Any help?
Nov 21 '12 #1
4 16124
Rabbit
12,516 Expert Mod 8TB
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.
Nov 21 '12 #2
KBeggs
3
Thank you so much for this. I'm relatively new to programming so I had no idea what to do.
Nov 21 '12 #3
KBeggs
3
I fixed those errors, but now have more:

Expand|Select|Wrap|Line Numbers
  1. proj2.c: In function âget_positive_valueâ:
  2. proj2.c:76: warning: control reaches end of non-void function
  3. proj2.c: In function âmainâ:
  4. proj2.c:57: warning: control reaches end of non-void function
  5. proj2.c:40: warning: âselectionâ is used uninitialized in this function
  6. proj2.c:44: warning: âwithdrawal_amtâ may be used uninitialized in this function
  7. proj2.c:45: warning: âtotal_withdrawalsâ may be used uninitialized in this function
  8. proj2.c:46: warning: âdeposit_amtâ may be used uninitialized in this function
  9. proj2.c:47: warning: âtotal_depositsâ may be used uninitialized in this function
:/
Nov 21 '12 #4
Rabbit
12,516 Expert Mod 8TB
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.
Nov 21 '12 #5

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

Similar topics

6
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. ...
4
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....
21
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...
5
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...
5
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...
1
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...
2
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...
12
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>...
10
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
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
jinu1996
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...

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.