我是一个初学者,此代码需要提供属性详细信息.它会自动选择房产类型作为房子.我该怎么办



我必须详细了解房产的长度、宽度,无论是否获得政府批准,然后是其成本和加10%税后的估计成本。输出没有提供选择属性类型的选项。

#include <stdio.h>
#include <stdbool.h>
int main()
{ 
char l, f, pte;
float length ,breadth,property_cost;
float cost_per_squarefeet;
bool approved_by_govt_OR_NOT;
printf("enter the lengthn");
scanf("%f" ,&length);
printf("enter the breadthn");
scanf("%f" ,&breadth);
printf("enter the cost per squarefeetn");
scanf("%f" ,&cost_per_squarefeet);
printf("enter property typen");
if(pte=='1')
{
printf("property type is landn");
}
else if(pte=='f')
{
printf("property type is flatn");
}
else
{
printf("property type is housen");
}
property_cost =(length*breadth*cost_per_squarefeet) * (10/100.0);
printf("property cost is %f" ,property_cost);
return(0);
}

输出

您忘记了scanf()用户输入。pte的值从未被设置,因此它既不等于"0";l〃;或";f";,而else语句将始终被执行。

pte未初始化,因为它是一个局部变量,所以它很可能是一栋房子,因为你当时正在读取内存中的任何内容。

您需要使用scanf()或类似的方法来获得用户的输入。

相关内容

最新更新