fork download
  1. # include <stdio.h>
  2.  
  3. struct Capacitor
  4. {
  5. char model[99];
  6. float capacitance;
  7. float voltage;
  8. float cost;
  9. };
  10.  
  11.  
  12. void displayCapacitorInfo(struct Capacitor array[])
  13. {
  14. for(int i = 0; i < 4;i++){
  15. printf("Capacitor %s \n", array[i].model);
  16. printf("\t* Capacitance: %.1f uF\n", array[i].capacitance);
  17. printf("\t* Voltage: %.1f V\n", array[i].voltage);
  18. printf("\t* Cost: $%.2f\n", array[i].cost);
  19. }
  20. }
  21.  
  22.  
  23.  
  24. int main(){
  25.  
  26. struct Capacitor capacitor1 = {"11-123U", 100, 25, 6.00};
  27.  
  28. struct Capacitor capacitor2 = {"65t91a", 22000, 20, 25.00};
  29.  
  30. printf("The model of the first capacitor is: %s \n", capacitor1.model);
  31. printf("Voltage of the second capacitor is: %f V \n", capacitor2.voltage);
  32.  
  33.  
  34. struct Capacitor capacitor3;
  35. printf("Type in a Model for capacitor3:");
  36. scanf("%s", capacitor3.model);
  37. printf("Type in a capacitance for capacitor3:");
  38. scanf("%f", &(capacitor3.capacitance));
  39. printf("Type in a voltage for capacitor3:");
  40. scanf("%f", &(capacitor3.voltage));
  41. printf("Type in a cost for capacitor3:");
  42. scanf("%f", &(capacitor3.cost));
  43.  
  44. struct Capacitor capacitor4; // A blank capacitor4 that will be populated by user's input INSIDE the array
  45.  
  46. struct Capacitor array[4] = {capacitor1, capacitor2, capacitor3, capacitor4};
  47.  
  48. //populating capacitor4 INSIDE the array by user's input
  49. printf("Type in a Model for capacitor4:");
  50. scanf("%s", array[3].model);
  51. printf("Type in a capacitance for capacitor4:");
  52. scanf("%f", &(array[3].capacitance));
  53. printf("Type in a voltage for capacitor4:");
  54. scanf("%f", &(array[3].voltage));
  55. printf("Type in a cost for capacitor4:");
  56. scanf("%f", &(array[3].cost));
  57.  
  58.  
  59. displayCapacitorInfo(array);
  60.  
  61.  
  62. return 0;
  63. }
  64.  
  65.  
  66.  
  67.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'main':
prog.c:25:7: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[99]' [-Wformat=]
 scanf("%s", &(capacitor3.model));
       ^
prog.c:38:7: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[99]' [-Wformat=]
 scanf("%s", &(capacitor4.model));
       ^
prog.c:34:18: warning: unused variable 'array' [-Wunused-variable]
 struct Capacitor array[4] = {capacitor1, capacitor2, capacitor3, capacitor4};
                  ^
prog.c: At top level:
prog.c:49:44: error: array type has incomplete element type 'struct capacitor'
 void displayCapacitorInfo(struct capacitor array[])
                                            ^
prog.c:49:34: warning: 'struct capacitor' declared inside parameter list
 void displayCapacitorInfo(struct capacitor array[])
                                  ^
prog.c:49:34: warning: its scope is only this definition or declaration, which is probably not what you want
stdout
Standard output is empty