// program 2.17 calculating the hight of a tree
#include <stdio.h>
int main(void)
{
long shorty = 0L; //shorty's hight in inches
long lofty = 0L; // lofty's hight in inches
long feet = 0L;
long inches = 0L;
long shorty_to_lofty = 0L; //distance from shorty to lofty in inches
long lofty_to_tree = 0L; //distance from lofty to tree in inches
const long inches_per_foot = 12L;
long tree_height = 0L;
//get lofty's height
printf("Enter lofty's height to the top of his/her head,in whole feet:");
scanf("ld%", &feet);
printf(" ...and then inches:");
scanf("%ld", &inches);
lofty = feet*inches_per_foot + inches;
//get shorty's height up to his eyes
printf("enter short's height up to his eyes,in whole feet:");
scanf("%ld", &feet);
printf(" ...and then inches:");
scanf("ld", &inches);
shorty = feet*inches_per_foot + inches;
//get the distance from shorty to lofty
printf("enter the distance between shorty and lofty ,in whole feet:");
scanf("%ld", &feet);
printf(" ...and then inches:");
scanf("ld", &inches);
shorty_to_lofty = feet*inches_per_foot + inches;
//get the distance from lofty to the tree
printf("finally enter the distance from lofty to the tree to the nearest foot:");
scanf("%ld", &feet);
lofty_to_tree = feet*inches_per_foot;
// the code to calculate the height of the tree will go here
// the code to display the result will go here
tree_height = (lofty - shorty) * (shorty_to_lofty + lofty_to_tree) / shorty_to_lofty + shorty;
printf("The height of the tree is %ld feet and %ld inches.\n",
tree_height/inches_per_foot,tree_height%inches_per_foot);
return 0;
}
uj5u.com熱心網友回復:
求人來啊,實在是沒辦法了。uj5u.com熱心網友回復:
這一行代碼的問題,自己改。scanf("ld%", &feet);
uj5u.com熱心網友回復:
在每一個scanf后加一個getchar()轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/113019.html
標籤:基礎類
上一篇:關于C++的一個問題
