Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define A 100
#define SIZE 9
typedef struct{
char Goods[20];
}Goods_g;
typedef struct{
char PortName[10];
}Ports_p;
int DisplayPort(Goods_g *G, Ports_p *P, float variables[]);
int Purchase(Goods_g *G, float variables[], float money); /*fixed the problem with the prototype first*/
int main()
{
Goods_g G[9]= {
{ "Fish" },
{ "Cotton" },
{ " Wood" },
{ "Coco" },
{ "Sugar" },
{ "Guns" },
{ "Textiles" },
{ "Tobacco" },
{ "Wine" },
};
Ports_p P[6] = {
{ "Sydney" },
{ "London" },
{ "LosAngles" },
{ "NewYork" },
{ "Paris" },
{ "Tokyo" },
};
char name[A];
int i;
int j;
int k;
float variables[SIZE];
float money = 1000;
printf("Please enter your name: ");
scanf("%s",name);
printf("Please select which port you want to start in: ");
scanf("%d",&i);
srand((unsigned)time(NULL));
for (j=0; j<SIZE; j++)
variables[j] = (rand()%26)/14.0f;
if ( i >= 1 && i <= 6 ) {
DisplayPort ( &G[k-1], &P[i-1], variables);
}
if ( k >=1 && k<= 9) {
Purchase(&G[k-1], variables, money); /*that's the function call fixed*/
}
return 0;
}
int DisplayPort(Goods_g *G, Ports_p *P, float variables[])
{
G->Fish = 50*variables[0];
G->Cotton = 80*variables[1];
G->Wood = 100*variables[2];
G->Coco = 140*variables[3];
G->Sugar = 350*variables[4];
G->Guns = 700*variables[5];
G->Textiles =1350*variables[6];
G->Tobacco =1900*variables[7];
G->Wine =2150*variables[8];
printf("Welcome to %s\n",P->PortName);
printf("The prices for the material is as follows\n");
printf("Fish=%f\n", G->Fish);
printf("Cotton=%f\n", G->Cotton);
printf("Wood=%f\n", G->Wood);
printf("Coco=%f\n", G->Coco);
printf("Sugar=%f\n", G->Sugar);
printf("Textiles=%f\n", G->Textiles);
printf("Tobacco=%f\n", G->Tobacco);
printf("Wine=%f\n", G->Wine);
return 0;
}
int Purchase(Goods_g *G, float variables[], float money) /*fixed definition*/
{
G->Fish = 50*variables[0];
G->Cotton = 80*variables[1];
G->Wood = 100*variables[2];
G->Coco = 140*variables[3];
G->Sugar = 350*variables[4];
G->Guns = 700*variables[5];
G->Textiles =1350*variables[6];
G->Tobacco =1900*variables[7];
G->Wine =2150*variables[8];
int amount;
float totals;
float totalm;
printf("How many individual units of %s do you want to buy: ", G->Goods);
scanf("%d", &amount);
totals = (int) G->Goods*amount;
totalm = money-totals;
printf("You have %f money left\n", totalm);
printf("You have %d unit(s) of %s\n",amount, G->Goods);
return 0;
}