Hello All,
I'm having a problem compiling my code and I can't see why...can someone please have a look and see what I might be doing wrong? Also my compiler is spitting out the following:
[machine1@cels159075 milasp5.c]% gcc milasp5.c
one.c: In function ‘displayBankRecord’:
one.c:40: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
Thanks for your consideration -
-
#include <stdio.h>
-
-
float get_startingbalance(void);
-
float getCntOfWithdrawls();
-
float getCntOfDeposits();
-
float getEachDeposit();
-
float getEachWithdrawl();
-
float checkBalance();
-
float calcAndDisplayBalance();
-
float displayBankRecord()
-
-
int main()
-
-
{
-
-
/* Declare Variables */
-
-
float deposits[50] = {0};
-
float withdrawals[50] = {0};
-
char first_name[20] = {0};
-
int num_withdrawals, num_deposits, x;
-
float start_bal;
-
float current_balance = 0;
-
float total_deposits = 0;
-
float total_withdrawals = 0;
-
float balance;
-
-
/* Output initial greeting */
-
-
printf("Welcome to the Banking System.\n\n");
-
-
printf("Please enter your first name: ");
-
scanf("%s", &first_name);
-
fflush(stdin);
-
-
printf("\nHello, %s.\n\n", first_name);
-
-
/* GET STARTING BALANCE */
-
-
float get_start_balance() {
-
-
float start_bal
-
-
do {
-
-
printf("%s, Please enter your current balance in dollars and cents: "); /* Prompt user for current balance. */
-
scanf("%f", &start_bal);
-
fflush(stdin);
-
-
if (start_bal < 0)
-
printf("Invalid entry. Starting balance must be at least zero!\n\n");
-
-
} while (start_bal < 0);
-
-
return start_bal;
-
-
} /* end function get starting balance */
-
-
/* GET NUMBER OF WITHDRAWALS */
-
-
float getCntOfWithdrawls() {
-
-
float num_withdrawls
-
-
do {
-
-
printf ("\nEnter the number of withdrawals: ");
-
scanf ("%i", &num_withdrawals);
-
printf ("\n");
-
fflush (stdin);
-
-
if (num_withdrawals < 0 || num_withdrawals > 50)
-
printf ("Error: Number of withdrawals must be between zero and 50, please re-enter!\n\n");
-
-
} while (num_withdrawals < 0 || num_withdrawals > 50);
-
-
return num_withdrawls;
-
-
} /* end function number of withdrawls */
-
-
/* GET NUMBER OF DEPOSITS */
-
-
float getCntOfDeposits() {
-
-
float num_deposits
-
-
do {
-
-
printf ("Enter the number of deposits: ");
-
scanf ("%i",&num_deposits);
-
printf ("\n");
-
fflush (stdin);
-
-
if ( num_deposits < 0 || num_deposits > 50)
-
printf ("Error: Number of deposits must be between 0 and 50, please re-enter!\n\n");
-
-
} while (num_deposits < 0 || num_deposits > 50); /* end do-while loop */
-
-
return num_deposits;
-
-
} /* end function number of deposits */
-
-
6 1992
You are defining functions inside main(). Maybe you omitted the } at the end of main()?
You are defining functions inside main(). Maybe you omitted the } at the end of main()?
When you fix that you'll be faced with a bunch of undefined variables as your no-arguments functions are no longer able to find the variables defined within main.
The simplest way to fix this is to move those variable definitions out of main in order to make them global variables. The right way to fix this is to change the function declarations to take input arguments.
Thank You All for your suggestions, I'm getting there, but I'm not there yet. I'm re-posting my code and the following error from my compiler:
[machine1@cels159075 one.c]% gcc one.c
one.c:154: warning: data definition has no type or storage class
one.c:154: error: conflicting types for ‘current_balance’
one.c:34: error: previous definition of ‘current_balance’ was here
one.c:154: error: initializer element is not constant
one.c: In function ‘checkBalance’:
one.c:203: error: break statement not within loop or switch
The line
current_balance = total_deposits + start_bal;
is not inside a function. I don't know which function it's supposed to go in, but it has to be in a function.
This error
one.c:203: error: break statement not within loop or switch
says exactly what it means. You have a meaningless break statement inside of an if.
Hope this helps some.
Edit:
You do know that you have to call these functions from main or your program will not use them, right?
gmdune, you are better off reading the error messages you are getting and trying to understand what they mean. You can't go on posting on the forum every time you get a compilation error. Better try to learn from the compiler errors and try to resolve the problems yourself.
Banfa 9,065
Expert Mod 8TB
Can I remind everyone here that we don't allow posting of complete solutions, particularly to course work questions. We have good reasons for this give in our posting guidelines.
gmdune, it would be worth while you going and reading those guidelines before posting further as breaking them can lead to official warning and site bans (note this isn't a warning just a friendly piece of advice).
As r035198x you should try to understand your compiler diagnostics or at the very least go to that line in your code and see what you can see that is wrong. You should also be aware that it is not uncommon for line given in a compiler diagnostic to actually be the line of code after the line with the error on it. The compiler gives the line at which it was able to detect that an error had been made not the line with the error.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: gomerpyl3 |
last post by:
I am trying to make a small system to record details for a small video
/ DVD shop - approx 200 members @ the mo
I wanted it to be able to do the following:
Check out a video / DVD
Return...
|
by: Alan Bashy |
last post by:
Please, guys, In need help with this. It is due in the next week. Please,
help me to implement the functions in this programm especially the first
three constructor. I need them guys. Please, help...
|
by: baustin75 |
last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie
only when debugging in php designer 2005
--------------------------------------------------------------------------------
...
|
by: Chris Travers |
last post by:
Hi all;
A few years ago, I set about porting a PHP application from MySQL to
PostgreSQL, after realizing that MySQL wasn't going to be able to handle it.
In order to do this, I built a light,...
|
by: metaperl |
last post by:
Hi,
I would like an IDE that shows me all methods and functions I can call
on a particular data item. For instance, iter() can be called on any
sequence, but it is not a method.
Nonetheless,...
|
by: Rex |
last post by:
Hi All - I have a question that I think MIGHT be of interest to a
number of us developers. I am somewhat new to VIsual Studio 2005 but
not new to VB. I am looking for ideas about quick and...
|
by: pauldepstein |
last post by:
#include <iostream>
using namespace std;
int main()
{
extern "C" int f(int, int);
|
by: asif929 |
last post by:
I need immediate help in writing a function program. I have to write a
program in functions and use array to store them. I am not familiar
with functions and i tried to create it but i fails to...
|
by: Brad Baker |
last post by:
I'm building a small web application - I started out placing all my code in
one file (config.aspx). As I continue to add code though it was becoming
very unwieldy.
After doing some searching...
|
by: gnawz |
last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) ...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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: 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...
|
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: 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,...
|
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...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |