Archived

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

Kiwi_Fella

Basic C conversion programme

Recommended Posts

Hi Guys, Been having a few probs with a very basic C coversion programme i''ve been trying to run for school. Basically the user enters his/her name and then asked to enter their weight in pounds and height in inches, I am then supposed to covert their weight to kilograms and height to centimeters and then spit out something saying bob jones you are 95kgs and 185cm tall, sounds easy but I cant work it out as i''ve only been learning C for a couple of weeks at college, heres my code that i''ve come up with and its probably all wrong so if anyone can give mne some tips or help me out i''d be grateful thanks alot Kiwi #include <stdio.h> int main() { int iWeight; int iHeight; char cName; cName[30]; printf("Please enter your name\n"); scanf("name\n"); printf("Please enter your height in inches\n"); scanf("%i",iWeight); return 0;

Share this post


Link to post
Share on other sites
I wrote that in another thread!!! cheater!!!

most of that is right though...but it wont run untill you close the main() function.


I'm not gonna do your homework for you...but here


      

void main();
{
//init varibles.


//get data


//change data form

//IE English -> Metric



//spit it back out


}



edit: i can't type

[edited by - MattS423 on November 1, 2002 4:07:55 PM]

Share this post


Link to post
Share on other sites
Some hints:


char cName;
cName[30];

scanf("name\n");


I would suggest re-reading whatever course material you have on strings (or use the net) to figure out why these are wrong.


This post qualifies for 100 per cent Canadian Content under the rulings of the Canadian Internet Commission and the Federal Ministry of Communication. There are four Americans who worked on this post, but they all have landed immigrant status, and have signed CRTC affidavits swearing that they drink beer, eat back bacon, drive snowmobiles and wear toques. Any resemblance between the Content of this post and the content of any American post is purely coincidental and not the intention of the poster or the various Internet Agencies of the Canadian Government who have screened these posts prior to bulk erasing in accordance with the policies of the Federal Internet Identity Board.

Share this post


Link to post
Share on other sites
quote:
Original post by MattS423
//IE English -> Metric



English -> Metric ... or more commonly known to the world as Imperial -> Metric


*Scribble with excessive amounts of loops and curls*

Share this post


Link to post
Share on other sites
quote:
Original post by Michalson

This post qualifies for 100 per cent Canadian Content under the rulings of the Canadian Internet Commission and the Federal Ministry of Communication. There are four Americans who worked on this post, but they all have landed immigrant status, and have signed CRTC affidavits swearing that they drink beer, eat back bacon, drive snowmobiles and wear toques. Any resemblance between the Content of this post and the content of any American post is purely coincidental and not the intention of the poster or the various Internet Agencies of the Canadian Government who have screened these posts prior to bulk erasing in accordance with the policies of the Federal Internet Identity Board.


LOL...nice one

Matt if you wrote that code you need to look up some info on strings (char *).....



_____________________________

And the Phoenix shall rise from the ashes...

--Thunder_Hawk -- ¦þ
______________________________

Share this post


Link to post
Share on other sites
quote:
Original post by MattS423
I''m not gonna do your homework for you...


Well, I will.


  
#include <stdio.h>

int main(void)
{
float lbs, inches;
char name[21];

printf("What is your name?\n");
gets(name);
printf("What is your weight in pounds?\n");
scanf("%f", &lbs);
printf(lbs<350?"Okay.\n":"Want a candy bar, fatty?\n");
printf("What is your height in inches?\n");
scanf("%f", &inches);
printf("Well, %s:\nYour weight in kilograms is %fkg\n", name, lbs*0.4535925f);
printf("and your height in centimeters is %fcm\n", inches*2.54f);

getchar(); getchar(); // Pause before quitting

return 0;
}


It will screw up if your full name is longer than 20 characters.

Share this post


Link to post
Share on other sites
Gotta agree with the others on this one. The last thing I'm going to do is your homework for you.

However, Michalson's post was rather (purposefully?) cryptic and mine won't be much better but the lines in red are the ones you need to concentrate on.

Find out what those lines do and you'll have better luck.

On another note: Why not just complete their homework so that when they get to the real world they're not sucking up jobs from those of us that know how to program?

Good programmers are happy that their code works.

Great programmers know their code works.


[edited by - Like2Byte on November 1, 2002 5:04:06 PM]

Share this post


Link to post
Share on other sites
well, actually I wrote some code for him in another thread...it wasn''t that though...

i think i gave him more than that...

Zorodius--
gosh...
I''m still in high school...if anybody is gonna do any homework around here it should be me! but I don''t think that we should just flat out do people''s homework for ''em.

i like

printf(lbs<350?"Okay.\n":"Want a candy bar, fatty?\n");

thats great. Kiwi''s teacher just might give him a few extra for that.

Share this post


Link to post
Share on other sites
Thanks alot guys,

I actually managed to get it going by myself which was good, now that I look at it dunno what I was thinking cause it was a pretty easy programme, thanks again guys appreciate the help

Kiwi

Share this post


Link to post
Share on other sites