Skip to main content
GameDev.net gamedev.net
🔒 Locked

Help WIth a Basic C programme

Started by Kiwi_Fella Oct 31, 2002 at 9:05 AM 6 replies 200+ views
Original Post
Kiwi_Fella
Kiwi_Fella
Hi All, I have just started Learning C programming at college and I''m quite stuck with a basic excercise we''ve been asked to complete, this is basically what we have to do. "Write a program to input your name, height in inches and weight in pounds, convert the height to centimeters and weight to kilograms and display the followoing results." 1 inch = 2.54 cm and 1 pound = 0.4546kg. Now I know this is extremely basic to most peeps on here but i''d appreciate if someone could give me a few tips on how I should set this out and what syntax to use cause im just going round in circles. Thanks alot Kiwi Fella
civguy
civguy
Since it''s C, use scanf() to read the variables.

Use a=b*c; to convert the values to different system.

Use printf(); to display the results.

And go to
http://msdn.microsoft.com/
to read more about scanf and printf.

Remember to initialize your variables before using them.

Go to newbie forum
http://www.gamedev.net/community/forums/forum.asp?forum_id=31
Kiwi_Fella
Kiwi_Fella
Thanks civguy,

I know about printf and scanf and also we have learnt about If,Else statements, the basics you know? but im unsure of how I go about setting this programme out, this is how im setting it out

#include <stdio.h>

int main()
{
char = height,weight,centimeters,kilograms,pounds;

Am I on the right track doing this?, if someone could fill in the gaps in in this so I can get an idea of how to set it out I''d appreciate it alot, Thanks again

Kiwi Fella
Kiwi_Fella
Kiwi_Fella
Thanks civguy,

I know about printf and scanf and also we have learnt about If,Else statements, the basics you know? but im unsure of how I go about setting this programme out, especially with declaring variables and when to declare them, this is how im setting it out

#include <stdio.h>

int main()
{
char = height,weight,centimeters,kilograms,pounds;
int = a,b,c

Am I on the right track doing this?, if someone could fill in the gaps in in this so I can get an idea of how to set it out I''d appreciate it alot, Thanks again

Kiwi Fella
civguy
civguy
quote:
Original post by Kiwi_Fella
char = height,weight,centimeters,kilograms,pounds;
int = a,b,c


Height, weight etc. aren''t characters. They are real numbers. Also, the = is wrong. Don''t you have a book where to learn these basics?

  
double height,weight,centimeters,kilograms,pounds;
int a,b,c;


Kiwi_Fella
Kiwi_Fella
Bro when I mean basic sh*t we''ve learnt I mean basic, I understand what some of the syntax means but actually applying it is another story, I just need someone to set this out so I can get an idea.
MattS423
MattS423
ok...i'll make this easy for you...
i'm not gonna do your homework for you though.




    
void main()
{
//init. varibles...i would go with 2 ints (iHeight, and iWeight) and a char (cName)

//please excuse the psydo-Hungarian notation


//Get the user input


printf("Hi, i'm Mr. Computer, whats your name? ");
scanf("%s",&cName); //check this, it's been awhile since i used

//scanf...

//etc....


//change the weight around

iWeight /*pounds*/ = iWeight*0.4546; //iWeight is now KG's


//spit it all back out

printf("Ok, %n weighs %i killograms and is %i meters tall\n",cName,iWeight,iHeight);

}



thats how i would do it..

edit: i messed up the code just a bit...

[edited by - MattS423 on October 31, 2002 3:22:43 PM]
Programmers of the world, UNTIE!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.