main must return int.. (problem)

This is a discussion on main must return int.. (problem) within the C Programming forums, part of the General Programming Boards category; Code: # include <stdio.h> void main() { char n[20]; float bs,hra,ns,pf; printf("enter name and basic salary"); scanf("%s%f",n,&bs); if (bs <=6500) ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    18

    main must return int.. (problem)

    Code:
     
    # include <stdio.h>
    void main()
    {
    char n[20];
    float bs,hra,ns,pf;
    printf("enter name and basic salary");
    scanf("%s%f",n,&bs);
    if (bs <=6500)
    hra =bs*.10;
    else if (bs,5000)
    hra=bs*.12;
    else
    hra=bs*.15;
    if (bs>2700)
    pf=bs*0.9;
    else
    pf=0;
    ns=bs+hra-pf;
    printf("hra=%2f\n",hra);
    printf("pf=%2f\n",pf);
    printf("ns=%2f\n",ns);
    }
    compiler gives out an error " `main' must return `int' "
    can anyone rectify this piece of code?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,803
    Well, you could change this:
    Code:
    void main()
    to:
    Code:
    int main()
    You may also need this at the end of the main function:
    Code:
    return 0;
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. why can't my perceptron learn correctly?
    By yann in forum C Programming
    Replies: 25
    Last Post: 10-15-2010, 12:26 AM
  2. Can anyone help?
    By javalurnin in forum C Programming
    Replies: 11
    Last Post: 12-02-2009, 05:02 AM
  3. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  4. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 10:00 PM
  5. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 09:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21