Code not compiling

Good day,
I have this code which always throws an error when I try to compile it. Please can anyone take a look and tell me where I got it wrong. Thank you all.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int main(){

float salary,l, frd inc tax, st tax, cty tax, soc security;
char name[20];

again:

printf("\n WELCOME TO BELLE'S SITE\n");
printf("\n Enter Your Name:");
scanf("%s",&name);
printf("\n\nEnter your salary:");
scanf("%f",&salary);

if(salary<=50000l && salary>=80000l)
 (frd inc tax =5100l);
	printf("\n your salary is:")


		 printf("\n THANKS FOR USING THIS SOFTWARE");
}
It appears you are using functions from stdio.h. That needs to be included like so...

1
2
3
4
5
6
7
8
9
#include <stdio.h>

int main(void)
{
 puts("Hello, World!");
 getchar();

 return 0;
}
Also avoid labels and goto.

And line 10 should be like so:
scanf("%s",name); // no '&'
Thanks for your responses so far but I still get errors on compile, even with the code modofied like this:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
#include <conio.h>
int main()
{

float salary,l, frd inc tax, st tax, cty tax, soc security;
char name[20];

again:

printf("\n WELCOME TO BELLE'S SITE\n");
printf("\n Enter Your Name:");
scanf("%s",name);
printf("\n\nEnter your salary:");
scanf("%f",salary);

if(salary<=50000l && salary>=80000l)
 (frd inc tax =5100l);
	printf("\n your salary is:")


		 printf("\n THANKS FOR USING THIS SOFTWARE");
}

The error is mainly on this line:
float salary,l, frd inc tax, st tax, cty tax, soc security;
Please tell me what to do next.
Thanks again.
Last edited on
They are almost all illegal variable names. About the only legal one is the 1st.
Thanks for your insight. I modified the code like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//*A PROGRAM THAT READS YOUR GROSS SALARY*//

#include <stdio.h>
#include <conio.h>
int main()
{
float salary,l, frd_inc_tax, st_tax, cty_tax, soc_security;
char name[20];
again:
printf("\n WELCOME TO BELLE'S SITE\n");
printf("\n Enter Your Name: ");
scanf("%s",name);
printf("\n Enter Your Salary: ");
scanf("%f",salary);
if(salary<=50000l && salary>=80000l)
 (frd_inc_tax=5100l);
	printf("\n Your salary is: ");
		 printf("\n THANKS FOR USING THIS SOFTWARE");
}
and there are no more compile errors but the program throws an error saying it has encountered an error and windows will close it. This happens after I input the name and salary and hitting enter for it to compute the tax.
Any help? I am running windows 7, if its any help.
Thanks again.
The scanf function takes pointers as arguments. You had to eliminate the '&' symbol from name because its already a char*; however, salary is not; it needs a '&' in front of it, i.e., &salary.
Last edited on
Thanks freddie1. Its starting to make sense now and it runs well without the program shutting down. But the output disappears as quickly as I hit enter. How can I make it stay until I close it myself. Please do not be angry with me; I'm just a learner.
Thanks for everything.
You will have to put something like "getchar()" at the end so that it stays open until you hit enter.
Just be aware that getch in the conio library is nonstandard; a thread stickied in the beginners forum discusses various standard workarounds and Linux/windows api functions to hold your console window open.
and if you want your program to display a message which say to press <Enter>to stop the program you can do something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 #include <stdio.h>
#include <conio.h>
int main()
{
// your source-code
 
. . . . . .  

printf();
printf();
printf();
printf("\n THANKS FOR USING THIS SOFTWARE");
printf("\n Press <Enter> to stop the execution of the program");
getchar();
}





Last edited on
If you were going to use enter anyway you could just use
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
I got that from the thread in the beginners forum, courtesy of Duoas. #include <limits>.
Topic archived. No new replies allowed.