Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions

Question

Write a Python program to check an input number is prime or not.

Answered: 1 week ago

Question

Write a program to check an input year is leap or not.

Answered: 1 week ago

Question

Use of assessments to determine trainees learning styles.

Answered: 1 week ago

Question

7. Discuss the advantages of embedded learning.

Answered: 1 week ago