Q: Convert a structure to function i.e passstructure to function What i got so f
ID: 3614197 • Letter: Q
Question
Q: Convert a structure to function i.e passstructure to functionWhat i got so far (using Visual C++6.0)following examples given to us in lecture:
#include <stdio.h>
struct car {
char model[20];
char regist_no[9];
int year;
};
void display(struct car);
void main (void)
{
struct car carNo1;
struct car carNo2;
struct car carNo3;
printf("HELLO! and WELCOME to this Car DataCollection Program ");
printf("Made by Yours Truly JAH SKIDO ");
printf("Please follow the INSTRUCTIONS below touse program effectively Do also please consider making a DONATIONto the programmer as he is in dire need of $$$ USD Currency ispreferred ");
printf(" Please enter your car model: ");
scanf("%s",&carNo1.model);
printf("Please enter your car's registrationnumber:");
scanf("%s",&carNo1.regist_no);
printf("Please enter the year model of the car:");
scanf("%d",&carNo1.year);
display(carNo1);
printf(" Please enter your car model: ");
scanf("%s",&carNo2.model);
printf("Please enter your car's registrationnumber:");
scanf("%s",&carNo2.regist_no);
printf("Please enter the year model of the car:");
scanf("%d",&carNo2.year);
display(carNo2);
printf(" Please enter your car model: ");
scanf("%s",&carNo3.model);
printf("Please enter your car's registrationnumber:");
scanf("%s",&carNo3.regist_no);
printf("Please enter the year model of the car:");
scanf("%d",&carNo3.year);
display(carNo3);
}
void display(struct car c1)
{
printf(" CAR 1 ");
printf("Model: %s ",c1.model);
printf("Car Registration Number: %s ",c1.regist_no);
printf("Year Model of car: %d ",c1.year);
}
void display(struct car c2)
{ */ THIS IS WHERE ERROROCCURS */
printf(" CAR 2 ");
printf("Model: %s ",c2.model);
printf("Car Registration Number: %s ",c2.regist_no);
printf("Year Model of car: %d ",c2.year);
}
void display(struct car c3)
{
printf(" CAR 3 ");
printf("Model: %s ",c3.model);
printf("Car Registration Number: %s ",c3.regist_no);
printf("Year Model of car: %d ",c3.year);
}
What I Need Help With:
I am getting this Error "(line 68) : errorC2084: function 'void __cdecl display(struct car)' already has abody"
I NEED THIS FOR REVISION PURPOSES..as I dontfully understand how to pass structure,pointers into functions. Sothis will aid my revison GREATLY.
THANKS IN ADVANCE
will give GOOD Rating
Tai
Explanation / Answer
please rate - thanks you defined the same function 3 times I made some other modifications also #include struct car { char model[20]; char regist_no[9]; int year; }; void display(car,int); int main (void) { car carNo1; car carNo2; car carNo3; printf("HELLO! and WELCOME to this CarData Collection Program "); printf("Made by Yours Truly JAH SKIDO "); printf("Please follow the INSTRUCTIONS below touse program effectively Do also please consider making a DONATIONto the programmer as he is in dire need of $$$ USD Currency ispreferred "); printf(" Please enter your car model: "); scanf("%s",&carNo1.model); printf("Please enter your car's registrationnumber:"); scanf("%s",&carNo1.regist_no); printf("Please enter the year model of the car:"); scanf("%d",&carNo1.year); display(carNo1,1); while ( getchar() != ' ' ); printf(" Please enter your car model: "); scanf("%s",&carNo2.model); printf("Please enter your car's registrationnumber:"); scanf("%s",&carNo2.regist_no); printf("Please enter the year model of the car:"); scanf("%d",&carNo2.year); display(carNo2,2); while ((ch = getchar()) != ' ' ); printf(" Please enter your car model: "); scanf("%s",&carNo3.model); printf("Please enter your car's registrationnumber:"); scanf("%s",&carNo3.regist_no); printf("Please enter the year model of the car:"); scanf("%d",&carNo3.year); display(carNo3,3); } void display(car c1,int i) { printf(" CAR %d ",i); printf("Model: %s ",c1.model); printf("Car Registration Number: %s ",c1.regist_no); printf("Year Model of car: %d ",c1.year); } Ideally if this is the entireprogram it should be in a loop #include struct car { char model[20]; char regist_no[9]; int year; }; void display(car,int); int main (void) { car carNo1; char ch; int i; printf("HELLO! and WELCOME to this Car DataCollection Program "); printf("Made by Yours Truly JAH SKIDO "); printf("Please follow the INSTRUCTIONS below touse program effectively Do also please consider making a DONATIONto the programmer as he is in dire need of $$$ USD Currency ispreferred "); for(i=1;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.