By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,412 Members | 2,882 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,412 IT Pros & Developers. It's quick & easy.

error: expected expression before '}' token

P: 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
Share this Question
Share on Google+
4 Replies


Rabbit
Expert Mod 10K+
P: 12,366
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

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

P: 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
Expert Mod 10K+
P: 12,366
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

Post your reply

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