Errors in code for Miracle C Compiler

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • top2000sd
    New Member
    • Dec 2009
    • 2

    Errors in code for Miracle C Compiler

    I'm trying to compile this code into miracle c compiler and I'm having problems, I appreciate if somebody help me with any mistakes in the code or write down the correct one. thanks..

    Code:
    #include <stdio.h>
    void main (void)
    {
    int age = 0;
    printf("Please enter your age:");
    scanf("%d",&age);
    }
    int difference = age - 18;
    if(difference < 0)
    printf("\nI’m sorry, you are too young to vote.");
    else
    printf("\nYou can vote!");
    }
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Line 2
    main returns int.

    int main()

    Line 7
    Superflous } closes main before the functions code has actually finished

    Line 8
    Unless you compiler is C99 compliant you can't declare variables in the middle of a function.

    Comment

    • top2000sd
      New Member
      • Dec 2009
      • 2

      #3
      Thank you very much for your great advise, I wanted to add a code saying that :

      If they are not old enough, display the number of years they have to wait. For example, age 17 has to wait 1 year, age 19 has been eligible for 1 year

      Where and how to write that? appreciate your help.

      Thanks in advance

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Basically you just need to modify the printf statements on lines 10 and 12 to print the value of difference as well as the additional text.

        Comment

        Working...