Public Group

#### Archived

This topic is now archived and is closed to further replies.

# A problem with this?

This topic is 5297 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey everyone, when i put this in and then open it up it works fine, but then when i put in a number and press enter it shuts itself off, any idea why it would do that? any way i can fix it? is this a common problem? thanks. /* Program 2.8 calculations on a table */ #include <stdio.h> #include <stdlib.h> void main() { float radius = 0.0f; float diameter = 0.0f; float circumference = 0.0f; float area = 0.0f; float Pi = 3.14159265f; printf("Input the diameter of the table:"); scanf("%f", diameter); radius = diameter/2.0f; circumference = 2.0f*Pi*radius; area = Pi*radius*radius; printf("\nThe circumference is %.2f", circumference); printf("\nThe area is %.2f\n", area); }

##### Share on other sites
Put getch() at the end. While you''re at it, learn to use C++ as there is no reason at all to use plain C.

##### Share on other sites
erm im using C becuase i got the game programming guru book (lots of people suggested it) but i need to know C to use it. So I''m going to learn C, then learn C++, then read the book so i have a basic knowledge of both before i start. Oh and i prolly should have mentioned that it gives me a windows error, not shuts down and it still does it.

##### Share on other sites
quote:
Original post by Talvern
Oh and i prolly should have mentioned that it gives me a windows error, not shuts down and it still does it.

Care to tell us what that error is?

Although from the looks of it, I think I know what''s wrong. Try...

scanf("%f", &diameter);

scanf() requires pointers to work with.

##### Share on other sites
Hey everyone, when i put this in and then open it up it works fine, but then when i put in a number and press enter it shuts itself off, any idea why it would do that? any way i can fix it?

a) Because console applications are intended to be run in a pre-existing console (a.k.a "DOS commnd prompt"). If you don''t have a console when the program starts up, the C run-time creates one but, as with every other resource, it must be destroyed when the program terminates.

b) Make a foo.bat file (or equivalent) and execute it instead of directly calling your executable:
foo.exe
pause

##### Share on other sites
quote:
Original post by RuneLancer
Care to tell us what that error is?

Although from the looks of it, I think I know what''s wrong. Try...

scanf("%f", &diameter);

scanf() requires pointers to work with.

Heh yeah, I found that out last night and didnt bother coming on the forums after that, thanks for the help though =D

1. 1
Rutin
67
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633420
• Total Posts
3011793
• ### Who's Online (See full list)

There are no registered users currently online

×