Hello guys. My question is on the title. This is just an exercise that I wanted to do before my final exam. It's quite hard for me to understand. I hope you can give me good explanation or any examples that are related to this question. Sorry for any grammatical errors. English is my 2nd language.
Question:
EXERCISE 1
Create a structure called Car. The members are brand and price.
In main( ) :
Create a structure array called C of size 5
Call function get_input(...), passing in array C
Call function display(....),p assing in array C
In function get_input(...) :
Get user input for brand and price.
In function display(....) :
Displaying all car records whose price is more than 80K
Sample output screen
Enter car brand : Honda
Enter car price : RM 79000.00
Enter car brand : Toyota
Enter car price : RM 108000.00
Enter car brand : BMW
Enter car price : RM 390800.00
Enter car brand : Kelisa
Enter car price : RM 32000.00
Enter car brand : Myvi
Enter car price : RM 45900.00
Car brand : Toyota
Car price : RM 108000.00
Car brand : BMW
Car price : RM 390800.00
My coding:
Errors:
Line 7: field 'get_input' declared as a function
line 8: filed 'display' declared as a function
line 9: warning: useless storage class specifier in empty declaration In function 'main':
line 14: expected '=', ',', ';', 'asm' or '_attribute_' before '{' token In function 'get_input':
line 21: expected statement before ')' token
line 24: 'C' undeclared (first use in this function)
line 24: (Each undeclared identifier is reported only once In function 'display'
line 31: 'C' undeclared (first use in this function)
line 34: 'else' without a previous 'if'
Question:
EXERCISE 1
Create a structure called Car. The members are brand and price.
In main( ) :
Create a structure array called C of size 5
Call function get_input(...), passing in array C
Call function display(....),p assing in array C
In function get_input(...) :
Get user input for brand and price.
In function display(....) :
Displaying all car records whose price is more than 80K
Sample output screen
Enter car brand : Honda
Enter car price : RM 79000.00
Enter car brand : Toyota
Enter car price : RM 108000.00
Enter car brand : BMW
Enter car price : RM 390800.00
Enter car brand : Kelisa
Enter car price : RM 32000.00
Enter car brand : Myvi
Enter car price : RM 45900.00
Car brand : Toyota
Car price : RM 108000.00
Car brand : BMW
Car price : RM 390800.00
My coding:
Code:
#include <stdio.h> struct CAR { char brand[20]; float price; float get_input(char brand, float price, int i); float display(char brand, float price, int i); }; int main() { struct CAR C[5] { float get_input(char brand, float price, int i); float display(char brand, float price, int i); } float get_input(char brand, float price, int i) { for(i = 0; i < 5; i++)) { printf("Enter car brand : "); scanf("%s", C[i].brand); printf("\nEnter car price : RM "); scanf("%f", &C[i].price); } } float display(char brand, float price, int i) { if (C[i].price > 80000) printf("\nCar brand : %s", C[i].brand); printf("\nCar price : RM %.2f", C[i].price); else printf("\n"); } }
Line 7: field 'get_input' declared as a function
line 8: filed 'display' declared as a function
line 9: warning: useless storage class specifier in empty declaration In function 'main':
line 14: expected '=', ',', ';', 'asm' or '_attribute_' before '{' token In function 'get_input':
line 21: expected statement before ')' token
line 24: 'C' undeclared (first use in this function)
line 24: (Each undeclared identifier is reported only once In function 'display'
line 31: 'C' undeclared (first use in this function)
line 34: 'else' without a previous 'if'
Comment