Here is my code:
#include <stdio.h>
#include <string.h>
#define Length 20
struct Capacitor
{
char Model[Length];
int Capacitance;
float Voltage;
float Cost;
};
void displayCapacitorInfo(struct Capacitor List[])
{
int i;
for (i = 0; i < 4; i++)
{
printf("Capacitor %s:\n\n", List[i].Model);
printf(" *Capacitance: %d uF\n", List[i].Capacitance);
printf(" *Voltage: %f V\n", List[i].Voltage);
printf(" *Cost: $%f\n", List[i].Cost);
printf("\n");
}
}
int main()
{
float Cost, Voltage;
int Capacitance;
char Model[Length];
struct Capacitor a;
struct Capacitor b;
struct Capacitor c;
struct Capacitor d;
strcpy(a.Model, "11-123U");
a.Capacitance = 100;
a.Voltage = 25;
a.Cost = 6.00;
strcpy(b.Model, "65T91a");
b.Capacitance = 22000;
b.Voltage = 20;
b.Cost = 25.00;
printf("Model number of 1st capacitor: %s\n", a.Model);
printf("Voltage of 2nd capacitor: %f V\n", b.Voltage);
printf("\n");
printf("Model number of 3rd capacitor:");
scanf("%s", &c.Model);
printf("\n");
printf("Capacitance of 3rd capacitor:");
scanf("%d", &c.Capacitance);
printf("\n");
printf("Voltage of 3rd capacitor:");
scanf("%f", &c.Voltage);
printf("\n");
printf("Cost of 3rd capacitor:");
scanf("%f", &c.Cost);
printf("\n\n");
printf("Model number of 4th capacitor:");
scanf("%s", &d.Model);
printf("\n");
printf("Capacitance of 4th capacitor:");
scanf("%d", &d.Capacitance);
printf("\n");
printf("Voltage of 4th capacitor:");
scanf("%f", &d.Voltage);
printf("\n");
printf("Cost of 4th capacitor:");
scanf("%f", &d.Cost);
printf("\n\n");
struct Capacitor List[] = { {a.Model, a.Capacitance, a.Voltage, a.Cost}, {b.Model, b.Capacitance, b.Voltage, b.Cost}, {c.Model, c.Capacitance, c.Voltage, c.Cost}, {d.Model, d.Capacitance, d.Voltage, d.Cost} };
displayCapacitorInfo(List);
return 0;
}
Output:
I am having trouble with my array List[], specifically when I try to input the model number of my capacitors. The Model element of structures a, b, c, and d produces a "initialization makes integer from pointer without a cast" warning when entered into the array List[].
What can I do to fix this?
Thanks for the help.
struct Capacitor List[] = {a, b, c, d};- Crowman