We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,386 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

HELP IT KEEPS GIVING ME SAME ERRORS

I am a newbie in programming and I'm using visual studio.
i typed in this

#include <stdio.h>
#include <conio.h>
#define PI 3.1416 

void main(void)
{                               

float radius, circumference, area;

radius = 2.5;

circumference = 2 * PI * radius;

area = PI * radius * radius;

printf("radius of a circle = %f cm\n", radius);
printf("circumference = %f cm\n", circumference); 
   printf("Area = %f sq cm\n", area);  
   getch();
} 

it gives me

1>------ Build started: Project: tryagn, Configuration: Debug Win32 ------
1>Build started 21/04/2012 5:31:18 PM.
1>InitializeBuildStatus:
1>  Touching "Debug\tryagn.unsuccessfulbuild".
1>ClCompile:
1>  tryagain.c
1>d:\vc\chap2\sln\tryagn\tryagain.c(4): error C2449: found '{' at file scope (missing function header?)
1>d:\vc\chap2\sln\tryagn\tryagain.c(14): error C2059: syntax error : '}'
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.29
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

What is wrong with it?

4
Contributors
4
Replies
5 Days
Discussion Span
1 Year Ago
Last Updated
5
Views
RichardLim
Newbie Poster
1 post since Apr 2012
Reputation Points: -3
Solved Threads: 0
Skill Endorsements: 0

I'm not sure if visual studio supports a deprecated library like conio.h and it's functions like getch(), try removing them

also use int main instead of void main

zeroliken
Nearly a Posting Virtuoso
1,346 posts since Nov 2011
Reputation Points: 214
Solved Threads: 205
Skill Endorsements: 14

do the following changes :

void main(void) to int main()

remove getch(), use header file "stdlib.h" and use system("pause") at place of getch()
It will hold the screen for you. (same as getch();)

use return 0 for returning nothing(same as void) in the end of the program.
return 0; is necessary because you are using an integer return type main function.

Shardendu
Newbie Poster
19 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

sorry for bad format reply...but i hope it will help :)

Shardendu
Newbie Poster
19 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This syntax error below tells me that you have only an open brace somewhere in your code. That is, there is no corresponding closing brace. But yet I do not see this error condition in your posted code. Are you sure you posted the faulty code?

> d:\vc\chap2\sln\tryagn\tryagain.c(4): error C2449: found '{' at file scope (missing function header?)
> 

I can only assume this second syntax error is related to the missing closing bracket.

> > d:\vc\chap2\sln\tryagn\tryagain.c(14): error C2059: syntax error : '}'
> 
> 
> 

How about posting the faulty tryagain.c code?

BobS0327
Junior Poster
185 posts since Feb 2008
Reputation Points: 35
Solved Threads: 24
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0661 seconds using 2.71MB