Thread: Is my typing correct

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    2

    Is my typing correct

    Code:
    #include <stdio.h>
    main()
    
    {
    float salary,tax,net_salary;
    int number of employees;
    printf("Enter the number of emloyee");
    scanf("%d",&number of employees);
    for(i<0;i<number of employees;i++)
    {
    
    printf("Enter the value of the salary.\n");
    scanf("%f",&salary);
    if(salary>1000)
    {tax=salary*0.15;
    net_salary=salary-tax;
    printf("The value of net salary is=%f",net_salary);
    }
    
    else if(600<salary<1000)
    {tax=salary*0.1;
    net_salary=salary-tax;
    printf("The value of the net salary is =%f",net_salary);
    }
    
    else(salary<600)
    {tax=0.03*salary;
    net_salary=salary-tax;
    printf("The value of the net salary is=%f",net_salary);
    }
    }

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    int main() not just " main() "

    int number of employees;
    you cant have spaces in variable names
    you have to write using an underscore if you want it to look like a space
    number_of_employees

    You have to learn how to indent your code so that it is easier to read for everybody, including you.

    you should change your %f to something like %.3f then you will only get three decimal places

    other stuff looks ok, just fix formatting and dont put a newline before 'else'

    also its usually a good idea to zero your ints and floats etc, its a good habit, so if they have no meaningful value to start with just set them to 0 when you declare them.
    sometimes its obvious that the e.g integer is immediately assigned after declaration but like i say its a good habit and will save you much bug hunting pain.
    Last edited by rogster001; 11-01-2010 at 10:48 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    2
    Thanks for the help , rogster001

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. i solved this recursion, is it correct?
    By jackhasf in forum C Programming
    Replies: 7
    Last Post: 12-21-2009, 05:49 AM
  2. Hi, Quiz C program Assignment updated
    By Eman in forum C Programming
    Replies: 19
    Last Post: 11-22-2009, 04:50 PM
  3. Linux for GNU/Linux is not correct?
    By password636 in forum Linux Programming
    Replies: 8
    Last Post: 03-31-2009, 08:30 PM
  4. Is this correct : passing strings?
    By socket in forum C Programming
    Replies: 15
    Last Post: 11-25-2008, 02:03 PM