LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-07-2004, 09:22 PM   #1
shams
Member
 
Registered: Jan 2004
Posts: 535

Rep: Reputation: 30
C code error


hi,
This is the code for file company.c:
/*Calculation of gross salary*/
main()
{
float bs,gs,da,hra;

printf("Enter your basic salary\n");
scanf("%f",&bs);

if(bs<1500);
{
hra=bs*10/100;
da=bs*90/100;
}
else
{
hra=500;
da=bs*98/100;
}
then i tried the gcc -o ..and there is the output:
root@localhost lbin]# gcc -o company company.c
company.c: In function `main':
company.c:14: error: parse error before "else"
company.c: At top level:
company.c:20: error: `bs' undeclared here (not in a function)
company.c:20: error: `hra' undeclared here (not in a function)
company.c:20: error: `da' undeclared here (not in a function)
company.c:20: warning: data definition has no type or storage class
company.c:21: error: parse error before string constant
company.c:21: warning: conflicting types for built-in function `printf'
company.c:21: warning: data definition has no type or storage class
plz help me where is the mistakes.
 
Old 07-07-2004, 09:37 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Add #include <stdio.h> to the top of the file and get rid of the ; at the end of your if(). That should take care of the problems for you.
 
Old 07-07-2004, 09:42 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
And there's a missing } at the end of the program
as well ... indentation helps ;)

Code:
main()
{
  float bs,gs,da,hra;

  printf("Enter your basic salary\n");
  scanf("%f",&bs);

  if(bs<1500)
    {
      hra=bs*10/100;
      da=bs*90/100;
    }
  else
    {
      hra=500;
      da=bs*98/100;
    }
}
Cheers,
Tink
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C code 'gets' error boxerboy Programming 6 08-28-2005 03:27 PM
User Preferences: Use HTML code instead of vB code? (vB code is overrated) stefanlasiewski LQ Suggestions & Feedback 5 07-26-2005 01:37 AM
LPRng error 'NONZERO RFC1179 ERROR CODE FROM SERVER' ivanscheers Linux - Networking 0 10-11-2004 02:50 AM
error with the code suchi_s Programming 2 09-30-2004 05:48 AM
Synaptic error: "sub-process /usr/bin/dpkg returned an error code (2)" firefly2442 Linux - Software 3 02-04-2004 06:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration