Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been trying to run this code on VS CODE but the following error shows up. I think my code is right and problem is with my compiler. If someone could help I would be really thankful.

The Code
#include <stdio.h>

int main()
{
    int age;
    printf("Enter your age");
    scanf("%d", age);
    if (age >= 18)
        printf("You are eligible to vote.");
     else 
        printf("You are not eligible to vote");
    return 0;
}




The ERROR

C:\Users\sidsa\Desktop\programming> cd "c:\Users\sidsa\Desktop\programming\" ; if ($?) { gcc voting eligibility.c -o voting eligibility } ; if ($?) { .\voting eligibility }
gcc.exe: error: voting: No such file or directory
gcc.exe: error: eligibility.c: No such file or directory
gcc.exe: error: eligibility: No such file or directory
gcc.exe: fatal error: no input files
compilation terminated.
PS C:\Users\sidsa\Desktop\programming>

What I have tried:

Tried running the code but the error keeps on showing.
Posted
Updated 17-Sep-20 6:28am
v2
Comments
bbirajdar 17-Sep-20 12:08pm    
You don't have C/C++ compiler installed on the path where you are running the program.

Follow this https://code.visualstudio.com/docs/languages/cpp
Siddharth Saurav - IIT [BHU] 17-Sep-20 12:17pm    
Could you elaborate how can i solve this. I am just a beginner in coding so I don't know how to fix this.
bbirajdar 17-Sep-20 12:18pm    
Follow the steps in the link above to install the C/C++ compiler in your VS code.
Richard MacCutchan 17-Sep-20 12:28pm    
That's why he is using gcc.

Firstly your code has a bug in the following line:
C++
//    scanf("%d", age); // you need the addressof operator for scanf as on the next line:
    scanf("%d", &age); // note the & operator

The remaining error messages are telling you that gcc cannot find a folder or file called voting, or eligibility.c. You need to save your file with the correct name in the correct location. For example, move to c:\Users\sidsa\Desktop\programming, and save the source file with the correct name: eligibility.c. You should then be able to enter the command:
gcc -o eligibility eligibility.c
 
Share this answer
 
Are you certain that the line
scanf ("%d", age)
is correct
Age is a variable passed by value, so may be you should pass its address
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900