Jump to content
  • Advertisement

Archived

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

Talvern

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!