Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define A 100
#define SIZE 2
typedef struct{
float Fish;
float Cotton;
}Goods_g;
typedef struct{
char Sydney[10]; /*!! you need more that a char for a string */
char London[10];
char LosAngles[10];
char NewYork[10];
char Paris[10];
char Tokyo[10];
}Ports_p;
int Sydney(Goods_g *G, Ports_p *P, float variables[]);
int London(Goods_g *G, Ports_p *P, float variables[]);
int LosAngles(Goods_g *G, Ports_p *P, float variables[]);
int NewYork(Goods_g *G, Ports_p *P, float variables[]);
int Paris(Goods_g *G, Ports_p *P, float variables[]);
int Tokyo(Goods_g *G, Ports_p *P, float variables[]);
int main()
{
Goods_g G;
Ports_p P;
char name[A];
int i;
//int x=1000;
int j;
float variables[SIZE];
printf("Please enter your name: ");
scanf("%s",name); /*!! No & here, name is an array */
printf("Please select which pont you want to start in: ");
scanf("%d",&i);
if(i==1)
printf("Welcome to Sydney\n");
if(i==2)
printf("Welcome to London\n");
if(i==3)
printf("Welcome to LosAngles\n");
if(i==4)
printf("Welcome to NewYork\n");
if(i==5)
printf("Welcome to Paris\n");
if(i==6)
printf("Welcome to Tokyo\n");
srand((unsigned)time(NULL));
for (j=0; j<2; j++)
variables[j] = (rand()%26)/14.0f;
strcpy( P.Sydney, "Sydney" );
strcpy( P.London, "Lndon" );
strcpy( P.LosAngles, "LosAngles");
strcpy( P.NewYork, "NewYork");
strcpy( P.Paris, "Paris");
strcpy( P.Tokyo, "Tokyo");
Sydney(&G, &P, variables);
London(&G, &P, variables);
LosAngles(&G, &P, variables);
NewYork(&G, &P, variables);
Paris(&G, &P, variables);
Tokyo(&G, &P, variables);
return 0;
}
int Sydney(Goods_g *G, Ports_p *P, float variables[])
{
G->Fish = 50*variables[0];
G->Cotton = 80*variables[1];
printf("Welcome to %s\n",P->Sydney);
printf("The prices for the material is as follows\n");
printf("Fish=%f\n", G->Fish);
printf("Cotton=%f\n", G->Cotton);
return 0;
}
int London(Goods_g *G, Ports_p *P, float variables[])
{
G->Fish = 50*variables[0];
G->Cotton = 80*variables[1];
printf("Welcome to %s\n",P->London);
printf("The prices for the material is as follows\n");
printf("Fish=%f\n", G->Fish);
printf("Cotton=%f\n", G->Cotton);
return 0;
}
int LosAngles(Goods_g *G, Ports_p *P, float variables[])
{
G->Fish = 50*variables[0];
G->Cotton = 80*variables[1];
printf("Welcome to %s\n",P->LosAngles);
printf("The prices for the material is as follows\n");
printf("Fish=%f\n", G->Fish);
printf("Cotton=%f\n", G->Cotton);
return 0;
}
int NewYork(Goods_g *G, Ports_p *P, float variables[])
{
G->Fish = 50*variables[0];
G->Cotton = 80*variables[1];
printf("Welcome to %s\n",P->NewYork);
printf("The prices for the material is as follows\n");
printf("Fish=%f\n", G->Fish);
printf("Cotton=%f\n", G->Cotton);
return 0;
}
int Paris(Goods_g *G, Ports_p *P, float variables[])
{
G->Fish = 50*variables[0];
G->Cotton = 80*variables[1];
printf("Welcome to %s\n",P->Paris);
printf("The prices for the material is as follows\n");
printf("Fish=%f\n", G->Fish);
printf("Cotton=%f\n", G->Cotton);
return 0;
}
int Tokyo(Goods_g *G, Ports_p *P, float variables[])
{
G->Fish = 50*variables[0];
G->Cotton = 80*variables[1];
printf("Welcome to %s\n",P->Tokyo);
printf("The prices for the material is as follows\n");
printf("Fish=%f\n", G->Fish);
printf("Cotton=%f\n", G->Cotton);
return 0;
}