patterncMinor
"Buy and Sell" game project
Viewed 0 times
buysellprojectgameand
Problem
This is a buy and sell game. I've revised it, though it's still unfinished. I would appreciate it if someone could review it again for me.
```
#include
#include
#include
#include
void end()
{
system("cls");
int P, L, choice;
printf(" * \n");
printf(" END OF GAME \n");
printf(" * \n");
if(choice == P)
main();
else if(choice == L)
exit(0);
}
int PhoenixDown(int *phoenixdown)
{
srand(time(NULL));
*phoenixdown=rand()%(1200-500+1)%650;
return *phoenixdown;
}
int ElixirEssence(int *elixiressence)
{
srand(time(NULL));
*elixiressence=rand()%(2100-1500+1)%910;\
return *elixiressence;
}
int PlatinumIngot(int *platinumingot)
{
srand(time(NULL));
*platinumingot=rand()%(7000-5000+1)%1950;
return *platinumingot;
}
int GoldenMateria(int *goldenmateria)
{
srand(time(NULL));
*goldenmateria=rand()%(5500-3500+1)%2600;
return *goldenmateria;
}
int Scarletite(int *scarletite)
{
srand(time(NULL));
*scarletite=rand()%(12000-8000+1)%6500;
return *scarletite;
}
int Adamantite(int *adamantite)
{
srand(time(NULL));
*adamantite=rand()%(30000-15000+1)%13500;
return *adamantite;
}
int DarkMatter(int *darkmatter)
{
srand(time(NULL));
*darkmatter=rand()%(70000-40000+1)%36400;
return *darkmatter;
}
int Trapezohedron(int *trapezohedron)
{
srand(time(NULL));
*trapezohedron=rand()%(90000-60000+1)%39000;
return *trapezohedron;
}
int buyitem(int x, int y)// function used to buy an item at any store//
{
int bought;
bought=x-y;
return bought; //returns the value of the difference between x and y//
}
void Tycoons(int gil,int onhand,int day,int debt, int phoenixdown, int elixiressence, int platinumingot,int goldenmateria, int scarletite,int adamantite, int darkmatter, int trapezohedron )//function used as a shop, it does not return anything//
{
int i, j, g, on, d, de, count, N, option,p, e,pl,gm,s,a,dm,t;
d=*day;
g=*gil;
de=*debt;
on=*onhand;
```
#include
#include
#include
#include
void end()
{
system("cls");
int P, L, choice;
printf(" * \n");
printf(" END OF GAME \n");
printf(" * \n");
if(choice == P)
main();
else if(choice == L)
exit(0);
}
int PhoenixDown(int *phoenixdown)
{
srand(time(NULL));
*phoenixdown=rand()%(1200-500+1)%650;
return *phoenixdown;
}
int ElixirEssence(int *elixiressence)
{
srand(time(NULL));
*elixiressence=rand()%(2100-1500+1)%910;\
return *elixiressence;
}
int PlatinumIngot(int *platinumingot)
{
srand(time(NULL));
*platinumingot=rand()%(7000-5000+1)%1950;
return *platinumingot;
}
int GoldenMateria(int *goldenmateria)
{
srand(time(NULL));
*goldenmateria=rand()%(5500-3500+1)%2600;
return *goldenmateria;
}
int Scarletite(int *scarletite)
{
srand(time(NULL));
*scarletite=rand()%(12000-8000+1)%6500;
return *scarletite;
}
int Adamantite(int *adamantite)
{
srand(time(NULL));
*adamantite=rand()%(30000-15000+1)%13500;
return *adamantite;
}
int DarkMatter(int *darkmatter)
{
srand(time(NULL));
*darkmatter=rand()%(70000-40000+1)%36400;
return *darkmatter;
}
int Trapezohedron(int *trapezohedron)
{
srand(time(NULL));
*trapezohedron=rand()%(90000-60000+1)%39000;
return *trapezohedron;
}
int buyitem(int x, int y)// function used to buy an item at any store//
{
int bought;
bought=x-y;
return bought; //returns the value of the difference between x and y//
}
void Tycoons(int gil,int onhand,int day,int debt, int phoenixdown, int elixiressence, int platinumingot,int goldenmateria, int scarletite,int adamantite, int darkmatter, int trapezohedron )//function used as a shop, it does not return anything//
{
int i, j, g, on, d, de, count, N, option,p, e,pl,gm,s,a,dm,t;
d=*day;
g=*gil;
de=*debt;
on=*onhand;
Solution
Are you familiar with structures and arrays in C?
Detailed critique of a minor part of your system:
I'm not keen on
You don't need the trailing blanks at the end of each line of the 'end of game' message.
You don't initialize any of
While it is possible in C (but not C++) to call
Detailed critique of a minor part of your system:
void end()
{
system("cls");
int P, L, choice;
printf(" *********** \n");
printf(" END OF GAME \n");
printf(" *********** \n");
if (choice == P)
main();
else if (choice == L)
exit(0);
}I'm not keen on
system("cls") as a way of clearing the screen, but on Windows, it works.You don't need the trailing blanks at the end of each line of the 'end of game' message.
You don't initialize any of
P, L or Choice (so they contain indeterminate garbage), but you compare Choice with P and if they're equal, you call main() once more; if Choice is equal to L, you exit with success (which is good), and otherwise you return. You should think hard about this. Presumably, you needed a prompt such as 'Play again (P) or Leave (L):' and then you need to get input for which 'P' and 'L' are possible inputs. You'd probably want to upshift what the user typed, too.While it is possible in C (but not C++) to call
main() again, it is aconventional to do so. On the whole, you'd be better off not doing so. Your main program should have a loop which invokes the game (a function call), and then calls the end() function to get the choice from the user. If the choice is 'P', then you loop and play the game again; otherwise, you exit the loop and then the whole program.Code Snippets
void end()
{
system("cls");
int P, L, choice;
printf(" *********** \n");
printf(" END OF GAME \n");
printf(" *********** \n");
if (choice == P)
main();
else if (choice == L)
exit(0);
}Context
StackExchange Code Review Q#14652, answer score: 3
Revisions (0)
No revisions yet.