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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started