Can'nt figure out problem
Hello
I wrote this small program that it askes for the user their name. After that the user has a option of going to any port but in this test it can only go to 1 single port. After the user has chosen there port a price list comes up with the products sold in the port. The prices for the product is generated by a ramdom number generator then multiplied by a number. But the program it's working I can'nt seem to be able to fix the mistakes. Can some one please point me out in the right direction.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define a 100
#define size 2
int variable(void);
int Sydney(Goods_g *G, x[size]);
typedef struct{
float Fish;
float Cotton;
}Goods_g;
typedef struct{
char Sydney;
}Ports_p;
int main()
{
Goods_g G;
Goods_g *G;
Ports_p P;
Ports_p *P;
char name[a];
int i;
int x;
x=1000;
printf("Please enter your name: ");
scanf("%s",&name);
printf("Please select which pont you want to start in: ");
scanf("%d",&i);
if(i=1)
printf("Welcome to Sydney\n");
if(i>1 || i<1)
printf(" you must enter 1\n");
return 0;
}
int variable(void)
{
int i;
float x[size];
srand((unsigned)time(NULL));
for (i=0; i<2; i++)
x[i] = (rand()%26)/14.0f;
return 0;
}
int Sydney(Goods_g *G, x[size])
{
G->Fish=50*x[0];
G->Cotton=80*x[1];
printf("Welcome to Sydney\n");
printf("The prices for the material is as follows\n);
printf("Fish=%f\n, G->Fish);
printf("Cotton=%f\n, G->Cotton);
return 0;
}
Problems calling function
I Made All the modifications suggested but I'am having problems calling the function. I can'nt seen to make the function cal corectly. I want the array from the function variable to return it to function main so I can then pass it on to function Sydney.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define a 100
#define size 9
typedef struct{
float Fish;
float Cotton;
typedef struct{
char Sydney;
}Ports_p;
float variable(void);
int Sydney(Goods_g *G, float x[]);
int main()
{
Goods_g Goods;
Goods_g *G;
G= &Goods;
Ports_p Ports;
Ports_p *P;
P= &Ports;
char name[a];
int i;
int x;
x=1000;
float y;
printf("Please enter your name: ");
scanf("%s",&name);
printf("Please select which pont you want to start in: ");
scanf("%d",&i);
if(i==1)
printf("Welcome to Sydney\n");
if(i>1 || i<0)
printf("You must enter 1\n");
y = variable();
Sydney(G,*y);
return 0;
}
float variable(void)
{
int i;
float x[size];
srand((unsigned)time(NULL));
for (i=0; i<9; i++)
x[i] = (rand()%26)/14.0f;
return 0;
}
int Sydney(Goods_g *G, float x[])
{
G->Fish==50*x[0];
G->Cotton==80*x[1];
printf("Welcome to Sydney\n");
printf("The prices for the material is as follows\n");
printf("Fish==%f\n, G->Fish\n");
printf("Cotton==%f\n, G->Cotton\n");
return 0;
}