Basic C conversion programme

Started by
8 comments, last by Kiwi_Fella 21 years, 5 months ago
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;
Advertisement
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]
Programmers of the world, UNTIE!
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.
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*
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || [email=lektrix@barrysworld.com]E-Mail Me[/email] ]
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 -- ¦þ
______________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
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.
You don't need to vote for the "lesser of two evils"! Learn about Instant Runoff Voting, the simple cure for a broken democracy!
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]
- Advice, eh? Well, besides working on your swing...you know, besides that...I'd have to think.
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.
Programmers of the world, UNTIE!
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
quote:Original post by Zorodius
printf(lbs<350?"Okay.\n":"Want a candy bar, fatty?\n");

LOL :D nice twist

This topic is closed to new replies.

Advertisement