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.
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");
}
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.
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.
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();
}
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>.