Quantcast

Maximum PC

It is currently Wed Oct 01, 2014 12:28 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: need help on my c program
PostPosted: Wed Jan 30, 2013 5:28 pm 
8086
8086
User avatar

Joined: Fri Jun 01, 2007 2:55 pm
Posts: 66
Location: California
I wrote a program to find the volume of a cube but I don't know why i'm getting error?

#include <stdio.h>
int main(void)
{
int h;
int w;
int l;
int a;

int v;





Printf("Please type in the legnth: ");
Scanf("%d ", &l);
Printf("Please type in the width:");
scanf("%d ", &w);
Printf("Please type in the height:");
scanf("%d ",&h);
a = h * w;
v = a * l;
printf( The volume of cube is %d ", v );
return 0;

I would apperciate if you could help me and explain what i did wrong. Thanks.


Top
  Profile  
 
 Post subject: Re: need help on my c program
PostPosted: Wed Jan 30, 2013 5:33 pm 
Smithfield
Smithfield

Joined: Sun Jun 18, 2006 7:37 pm
Posts: 5297
If that's your code verbatim...

  • You have capitals in some of your scanf and printf calls
  • You're missing a " in the last printf call.

Otherwise it runs just fine.


Top
  Profile  
 
 Post subject: Re: need help on my c program
PostPosted: Wed Jan 30, 2013 6:23 pm 
8086
8086
User avatar

Joined: Fri Jun 01, 2007 2:55 pm
Posts: 66
Location: California
Thanks latios. Did everything you told me and it worked. But what I don't get is why do I have to type in length twice? I don't see anything in the code that show's why I have to.


Top
  Profile  
 
 Post subject: Re: need help on my c program
PostPosted: Wed Jan 30, 2013 8:14 pm 
Smithfield
Smithfield

Joined: Sun Jun 18, 2006 7:37 pm
Posts: 5297
I ran this through gcc, no problems encountered.


Top
  Profile  
 
 Post subject: Re: need help on my c program
PostPosted: Wed Jan 30, 2013 10:33 pm 
8086
8086
User avatar

Joined: Fri Jun 01, 2007 2:55 pm
Posts: 66
Location: California
Image

As you can see from the picture i had to type length twice. Which is weird. I'll try to compile it again. I'm using microsoft's developer command prompt to compile it.


Top
  Profile  
 
 Post subject: Re: need help on my c program
PostPosted: Wed Jan 30, 2013 10:35 pm 
8086
8086
User avatar

Joined: Fri Jun 01, 2007 2:55 pm
Posts: 66
Location: California
revised code:
#include <stdio.h>
int main(void)
{
int h;
int w;
int l;
int a;

int v;





printf("Please type in the legnth:");
scanf("%d ", &l);
printf("Please type in the width:");
scanf("%d ", &w);
printf("Please type in the height:");
scanf("%d ",&h);
a = h * w;
v = a * l;
printf( "The volume of cube is %d ", v );
return 0;

}


Top
  Profile  
 
 Post subject: Re: need help on my c program
PostPosted: Wed Jan 30, 2013 11:34 pm 
Smithfield
Smithfield

Joined: Sun Jun 18, 2006 7:37 pm
Posts: 5297
Part of me wants to say if you're semi-serious about this, you should install a VM like VirtualBox and get a Linux distro up and running. Mostly because many development environments use gcc, so it'd be good to learn with that.

If you want something that offers debugging that won't scare the piss out of beginners (because gdb has a sharp learning curve), I'd recommend Visual Studio Express.

But either way, I ran your code and nothing odd happened.


Top
  Profile  
 
 Post subject: Re: need help on my c program
PostPosted: Thu Mar 07, 2013 2:11 am 
8086
8086

Joined: Thu Mar 07, 2013 12:33 am
Posts: 1
C programming is a good language and if you want to expose more on this language try to more research and get the best book to master the C Library is with no doubt "The Standard C Library" by P.J. Plauger.


Top
  Profile  
 
 Post subject: Re: need help on my c program
PostPosted: Fri Mar 08, 2013 1:49 pm 
Smithfield
Smithfield

Joined: Sun Jun 18, 2006 7:37 pm
Posts: 5297
The best C book is this: http://www.amazon.com/C-Programming-Lan ... g+Language


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.