Your time and energy is most appreciated
/* In the space provided below write a C program that asks the user to enter the address and the price of a dozen for-sale residential properties in Santa Monica and stores them by their address, price, and type (i.e., condo, single-family home, or land) in an array of structures. It then prints the information for those properties which are under 1 million dollars. Then using the embed icon shown above, insert screenshots demoing the execution of your code. */
Please advise. ie when I type in the address 1439 Cedar Ave, it takes Cedar Ave as seperate prompts, when its actually the address and a part of the first prompt.
#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");
}
}
}```
%sonly reads one word (as you have found). Usefgetsto get the whole line. Don't forget to remove the trailing newline character if you don't want to store that.2forn?