Question: C: Fix syntax errors: #include #include #include #define N 8 typedef struct battleship { char name[30]; char type[3]; char country[20]; int numGuns; int bore; float

C:

Fix syntax errors:

#include

#include

#include

#define N 8

typedef struct battleship {

char name[30];

char type[3];

char country[20];

int numGuns;

int bore;

float displacement;

}

BattleShip;

void getBattleShip(BattleShip b[], int num) {

int i;

for(i = 0; i

printf("Enter Name: ");

scanf("%s", b[i]).name);

getchar();

printf("Enter Type: ");

scanf("%s", b[i]).type);

getchar();

printf("Enter Country: ");

scanf("%s", b[i]).country);

getchar();

printf("Enter NumGuns: ");

scanf("%d", &b[i]).numGuns);

printf("Enter Bore: ");

scanf("%d", &b[i]).bore);

printf("Enter Displacement: ");

scanf("%f", &b[i]).displacement);

printf(" )");

}

}

void displayBattleship(BattleShip b[], int num){

int i;

printf(" ");

printf("NAME | TYPE | COUNTRY | NUMGUNS | BORE | DISPLACEMENT ");

printf(" ");

for (i = 0; i < num; i++) {

printf("%s ", b[i].name);

printf("%s ", b[i].type);

printf("%s ", b[i].country);

printf("%d ", b[i].numGuns);

printf("%d ", b[i].bore);

printf("%0f", b[i].displacement);

printf(" ");

}

}

float getAvgNumGuns(BattleShip b[], int num){

int i;

float sum = 0.0;

for(i = 0; i < num; i++) {

sum += b[i].numGuns;

}

return sum/num;

}

int main() {

BattleShip bs[N] = {0} ;

int count;

printf("Enter Number of records: ");

getBattleShip(bs, count);

displayBattleship(bs, count);

printf("Average Num Guns: %.2f", getAvgNumGuns(bs, count));

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!