c - C 编程。如何在结构数组中传递字符串
问题描述
非常感谢您的时间和精力
/* 在下面提供的空白处编写一个 C 程序,要求用户输入圣莫尼卡一打待售住宅物业的地址和价格,并按地址、价格和类型(即公寓、单身-家庭住宅或土地)在一系列结构中。然后它会打印那些低于 100 万美元的房产的信息。然后使用上面显示的嵌入图标,插入演示代码执行的屏幕截图。*/
请指教。即,当我输入地址 1439 Cedar Ave 时,它会将Cedar Ave作为单独的提示,而它实际上是地址和第一个提示的一部分。
#include <string.h>
//gotta make the structure first:
//declare properties as struct (short for structure) so that
//the address, type and price all go under properties
struct property {
char address[100];
char type[100];
double price;
};
int main() {
int n,i;//declare i
struct property p[2];
//ask how many properties to add, this'll determine the amount of iterations
printf("Enter how many properties you want to add: ");
scanf("%d",&n);
//save previous input in &n and iterates/asks that many times about property info
for (i = 0; i < n; i++) {
//name + address
printf("Property #%d\n",i + 1);
printf("Address: ");
scanf("%s", &p[i].address); //input goes into structure
printf("\n");
//property type
printf("Enter type: \n");
scanf("%s", &p[i].type); //input goes into structure
printf("\n");
//price
printf("Enter price: \n");
scanf("%lf", &p[i].price); //input goes into structure
printf("\n");
//makes a space to seperate different properties
printf("\n");
}
printf("\nResidential properties in Santa Monica for sale under $1M: \n");
printf("\n");
//this for loop filters out the properties by price
//excludes properties worth MORE than $1M
//prints rest of properties UNDER $1M
for (i = 0; i <n; i++) {
if (p[i].price < 1000000) {
printf("Property %d:\n", i + 1);
printf("Address: %s\n", p[i].address);
printf("Type: %s\n", p[i].type);
printf("Price: %lf\n", p[i].price);
printf("\n");
}
}
}```
解决方案
推荐阅读
- android - 未处理的异常:键入“列表”
' 不是 'String' 类型的子类型 无法获取 json 数据 - swift - 视图中的 AVFoundation 摄像头
- azure - Azure 与服务总线主题的集成
- clojure - cider-connect-clj 无法连接到 nrepl.server/start-server
- excel - 将标题转换为单元格并加入
- spring - 创建 bean 'kafkaMessageChannelBinder' 定义的 org.springframework.cloud.stream.binder.kafka.config.KafkaBinderConfiguration 时出错:
- keras - 无效参数:在空标签后面看到一个非空标签(索引 >= num_classes - 1)
- c# - 信号量锁导致死锁
- python - Heroku 部署问题 - 找不到 python 应用程序
- python - 如何使sympi排列公式以使分子中的最高阶系数为1