Stupid C program homework. NEED HELP!!!!!

thespeakerbox

Platinum Member
Nov 19, 2004
2,654
0
71
I downloaded bloodshed, cause my moron teacher didnt give us anything to go by.
The first day of class and she hands out a paper that says
"write a program to calculate the volume of a box"

I cant get the program to work at all.
I named it a .c file and when i hit compile & run a blank screen comes up.
This is what i have so far.

CAN SOMEONE HELP ME!!!

/*Homework assignment 1 */
/*Compute the volume of a box*/
#include <stdio.h>
void main()
{
int length, width, height;
int volume;
scanf ("%d", &length),
scanf ("%d", &width),
scanf ("%d", &height),
volume= length * width * height;
printf("volume=%d \n ", volume);
}
 

JustAnAverageGuy

Diamond Member
Aug 1, 2003
9,057
0
76
If it's just a command line program this should work.

This assumes you don't have to actually make sure it's a number though :)

This isn't a homework forum either :p
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
Is it possible that you're just getting a blank screen because it's waiting for you to enter the data that you're prompting for in the scanf statements?
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
Originally posted by: JustAnAverageGuy
If it's just a command line program this should work.

This assumes you don't have to actually make sure it's a number though :)

This isn't a homework forum either :p

BTW, even if you did want to use C++, I would probably use #include <iostream> rather than #include <iostream.h> and then each of the iostream related classes (cout, endl, etc) would all be the std namespace.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Originally posted by: oog
Is it possible that you're just getting a blank screen because it's waiting for you to enter the data that you're prompting for in the scanf statements?
:thumbsup:

 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
Add:

getch();

to request character input, thusly having the window remain on your screen.
 

M0oG0oGaiPan

Diamond Member
Dec 7, 2000
7,858
2
0
digitalgamedeals.com
Originally posted by: fs5
Originally posted by: Kyteland
Originally posted by: thespeakerbox
CAN SOMEONE HELP ME!!!
I ran your code and got this output:
2
3
4
volume=24
As suggested, try supplying your program with input. :p

ROFL

Lol, you could add a line above your scanf statements like.
printf("Type some numbers here\n");

Just to remind yourself.
 

bersl2

Golden Member
Aug 2, 2004
1,617
0
0
Originally posted by: xtknight
Add:

getch();

to request character input, thusly having the window remain on your screen.

IIRC getch() is not ANSI C.
 

Darien

Platinum Member
Feb 27, 2002
2,817
1
0
Originally posted by: thespeakerbox
I downloaded bloodshed, cause my moron teacher didnt give us anything to go by.

Yes, because the teacher needs to tell you to buy software to compile C code. Anyways, Bloodshed is quite nice. No need to buy some elaborate IDE when you're just starting out.

...go vim!

/runs from the emacs crowd