请帮忙.这个简单的程序假设计算用户输入他们想要的每个房子的数量.每个房子增加的窗户乘以它.并且对备件的总量应用1%以上的窗口.为什么备件不工作?
/*************************************
* PROGRAM: WindowCalculator
* AUTHOR: Matthew Nickles
* DATE: 9/6/2018
* NOTES: This is for educational purposes, the program calculates
* how many windows for each house plan a city builder would get.
**************************************/
/* PREPROCESSOR COMMANDS */
#include <stdio.h>
/* MAIN PROCESSING CONTROL */
int main()
{
/* VARIABLE DECLARATIONS */
int MontgomeryHouses; /*20 Windows per a house*/
int KetteringHouses; /*15 Windows per a house*/
int SaxonHouses; /*12 Windows per a house*/
int TotalWindows; /*Total calculation of all windows*/
int SpareWindows; /*How many spare windows if you wanted 1% of total*/
/* WINDOWS PER HOUSE ALGORITHM */
printf("\n How many Montgomery Houses do you wish to build? They have 20 windows. ");
scanf("\n%d", &MontgomeryHouses);
fflush(stdin);
printf("\n How many Kettering Houses do you wish to build? They have 15 windows. ");
scanf("\n%d", &KetteringHouses);
fflush(stdin);
printf("\n How many Saxon Houses do you wish to build? They have 12 windows. ");
scanf("\n%d", &SaxonHouses);
fflush(stdin);
/* CALCULATE TOTAL WINDOWS*/
TotalWindows = (MontgomeryHouses * 20) + (KetteringHouses * 15)
+ (SaxonHouses * 12);
SpareWindows = TotalWindows * 0.01;
/* DISPLAY OUTPUT*/
printf("The spare windows needed &d are windows.\n",SpareWindows);
fflush(stdin);
printf("\nThe total amount of windows needed for all houses are %d windows.\n",TotalWindows);
fflush(stdin);
return 0;
}
/* END OF PROGRAM */
Run Code Online (Sandbox Code Playgroud)
你的逻辑完全没问题.这只是一个很小的语法错误.在这一行:
printf("The spare windows needed &d are windows.\n",SpareWindows);
&d应该被替换%d.
我认为你只是忽略了它,因为其他部分是完美的.
| 归档时间: |
|
| 查看次数: |
54 次 |
| 最近记录: |