我是新来的 [英] I'm new

查看:58
本文介绍了我是新来的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我有C课。我必须为我的

教师编写这个程序,他已经发布了软拷贝和算法。但是

我的问题是我必须将米转换成英尺,在此我必须

输出不仅是脚而且还有英寸现在我认为我已编码

脚的计算正确但是。我不知道如何将

剩余量发送到英寸并重新计算它并显示

计算这里是我迄今为止编码的内容。


#include< stdio.h>


#define因子2.54

int main(void)


{


浮动HM / *高度米* /

浮动INCHES / *高度(英寸)(后来调整到几英寸

身高)* /

浮动FEET / *全尺高度部分* /


/ *标题和积分* /

printf(高度转换程序\ n);

printf(由Randolph Gibson设计 - 2001年1月15日\ n ;);

printf(由罗马贝克编写 - 2005年9月\ n \\ nnn);


/ *说明* /

printf("这个程序会将人的身高从米数转换为%);

printf(以英尺和英寸为单位(四舍五入到最接近的英寸)和\
");

的printf(QUOT;在屏幕上显示结果。高度必须为\ n);

printf(以公制单位输入并包含小数部分。\ n);

printf(" The andwer将以整英尺和英寸显示。


/ *请求HM * /

printf(" Enter人的身高(米):);

scanf(%f,& HM);


/ * claculate and store数字* /

INCHES = HM * 100 / FACTOR;

FEET = INCHES / 12;


/ *显示答案* /

printf(\ n高度等于%.0f英尺和)


返回(0);

}


这里是带有我的教师算法的页面
http://www.gibson.vero-beach.fl.us/c...all/prj02.html


抱歉,我不能解释这个,我现在就迷路了

Ok so I have this class for C. I have to write this program for my
instructor, where he has already posted the softcopy and algorithm. But
my question is I have to convert meters to feet and in this I have to
output not only the feet but also the inches now I think I have coded
the feet calculation properly but. I don''t know how to send the
remainder to inches and than recalculate it and display that
calculation here is what I have coded this so far.

#include <stdio.h>

#define FACTOR 2.54

int main (void)

{

float HM /*hight in meters*/
float INCHES /*hight in inches (later adjust to just inches of
height)*/
float FEET /*whole feet portion of height*/

/*title and credits*/
printf ("Height Converting Program\n");
printf ("Designed by Randolph Gibson - 15 january 2001\n");
printf ("Coded by Rome Baker - September 2005\n\n");

/*explanation*/
printf ("This program will convert a person?s height from meters\n");
printf ("into feet and inches (rounded to the nearest inch) and \n");
printf ("display the result on the screen. The height must be\n");
printf ("entered in metric units and contain decimal portions.\n");
printf ("The andwer will be displayed in whole feet and inches.\n\n");

/*requesting HM*/
printf ("Enter the person?s height in meters:");
scanf ("%f", &HM);

/*claculate and store numbers*/
INCHES = HM * 100 / FACTOR;
FEET = INCHES / 12;

/*display answers*/
printf ("\nThe height is equivilant to %.0f feet and ")

return (0);
}

and here is the page with my instructors algorithm
http://www.gibson.vero-beach.fl.us/c...all/prj02.html

sorry i cant explain this better i am just lost right now

推荐答案

" glitter boy" <螺** @ nerdshack.com>在消息中写道

新闻:11 ********************** @ g43g2000cwa.googlegr oups.com ...


您必须自己编写代码。如果转换和舍入不是明确的,那么这里的例子就是:


h_in_meters = 1.8;


h_in_inches = h_in_meters *每米100 / *厘米* / /每英寸2.54 / *厘米* /; / *

< 71 - 当打印为D1时,舍入到最近((int)(0.5 + being_rounded))* *

h_in_foots = h_in_inches / 12; / *< 6 - 打印时打印,如果打印为

D2向下舍入(floor())* /


现在获得D3:


h_in_inches2 = h_in_inches - floor(h_in_foots)* 12; / *< 11 - 当打印为D3时,最接近
(如上所述)* *

HTH,

Alex
"glitter boy" <lo**@nerdshack.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...

You must write the code yourself. If the conversion and rounding aren''t
clear, here''s example:

h_in_meters = 1.8;

h_in_inches = h_in_meters * 100/*cm per meter*/ / 2.54 /*cm per inch */; /*
< 71 -- round to nearest ((int)(0.5+being_rounded)) when printing as D1 */

h_in_foots = h_in_inches / 12; /* < 6 -- round when printing, if printing as
D2 round down (floor()) */

now to get D3:

h_in_inches2 = h_in_inches - floor(h_in_foots) * 12; /* < 11 -- round to
nearest (as pointed above) when printing as D3 */

HTH,
Alex


感谢您的帮助。

我已完成编码,我的代码无错误。

但是当我运行程序我得到-1错误

任何sugestions?


~罗马

Thank you for your help.
I have finished codeing and my code will complie with no errors.
But when I run the program I get a -1 error
Any sugestions?

~Rome

glitter boy写道:
glitter boy wrote:
好的,所以我有这个C课。我必须为我的
讲师编写这个程序,他已经发布了软拷贝和算法。但是我的问题是我必须将米转换成英尺,在这里我不仅要输出脚而且输出英寸现在我认为我已经编码好了脚计算但是。我不知道如何将
剩余部分发送到英寸并重新计算它并显示这里的计算是我迄今为止编码的。


[...]浮动HM / *高度米* /
漂浮INCHES / *高英寸(后来调整到几英寸高度) * /
浮动FEET / *整个脚的高度部分* /
Ok so I have this class for C. I have to write this program for my
instructor, where he has already posted the softcopy and algorithm. But
my question is I have to convert meters to feet and in this I have to
output not only the feet but also the inches now I think I have coded
the feet calculation properly but. I don''t know how to send the
remainder to inches and than recalculate it and display that
calculation here is what I have coded this so far.
[...] float HM /*hight in meters*/
float INCHES /*hight in inches (later adjust to just inches of
height)*/
float FEET /*whole feet portion of height*/




不用那些分号会杀了你。通常只在命名宏中使用

全部大写。


试试看你能否知道这里发生了什么:


#include< stdio.h>

#include< math.h>


#define FACTOR 2.54

int main(无效)

{


double height_in_meters;

double inch_portion_of_height;


double foot_portion_of_height;

printf(" Height Convertion Program\\\
"

"在屏幕上显示结果。必须以公制单位输入并包含小数部分才能输入。

" \ n"

"答案将以整个英尺显示,并且

inches.\\\
\ n);


做{

printf(以米为单位输入此人的身高:);

fflush(stdout);

scanf("%lf",& height_in_meters);

if(height_in_meters< = 0)

printf("我们只处理有高度的人> 0.(\\ nn);

} while(height_in_meters< = 0);


inch_portion_of_height = height_in_meters * 100 / FACTOR;

foot_portion_of_height = floor(inch_portion_of_height / 12);

inch_portion_of_height - = 12 * foot_portion_of_height;


printf(" \ n height is equivilant to%。0f''%。0f\"。\ n",

foot_portion_of_height,inch_portion_of_height);


返回0;

}



leaving off those semicolons will kill you. It is conventional to use
all uppercase only in naming macros.

Try seeing if you can tell what''s happening here:

#include <stdio.h>
#include <math.h>

#define FACTOR 2.54

int main(void)
{

double height_in_meters;
double inch_portion_of_height;

double foot_portion_of_height;
printf("Height Convertion Program\n"
"Designed by Randolph Gibson - 15 january 2001\n"
"Coded by Rome Baker - September 2005\n\n"
"This program will convert a person''s height from meters\n"
"into feet and inches (rounded to the nearest inch) and \n"
"display the result on the screen. The height must be\n"
"entered in metric units and contain decimal portions.\n"
"The answer will be displayed in whole feet and "
"inches.\n\n");

do {
printf("Enter the person''s height in meters: ");
fflush(stdout);
scanf("%lf", &height_in_meters);
if (height_in_meters <= 0)
printf("We deal only in people with heights > 0.\n");
} while (height_in_meters <= 0);

inch_portion_of_height = height_in_meters * 100 / FACTOR;
foot_portion_of_height = floor(inch_portion_of_height / 12);
inch_portion_of_height -= 12 * foot_portion_of_height;

printf("\nThe height is equivilant to %.0f''%.0f\".\n",
foot_portion_of_height, inch_portion_of_height);

return 0;
}


这篇关于我是新来的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆