Hi I’m a beginner on C++, I try to make a guess number game, what I do is make a random number guess it , and give back how many times user make, I add a char[] for get 5 times history and read it, the question is I try to let user choose delete one of history them choose, and add new game data in there.
#include <iostream>
#include <ctime>
int randomnumber(int rad){
srand(time(NULL));
rad = rand()%1000;
return rad;
}
int main()
{
int bk =0;
int time;
int n = 0;
char his[5];
while(bk != 1){
int user = 0;
printf(" game menun enter 1 for start gamen enter 2 for check history n enter 3 for finish game");
std::cin >> (user);
if(user == 1)
{
printf("walcome to the find number game!n this number will be between 1 to 1000n ");
time = 0;
int rnum = randomnumber(1);
int unum;
//printf("%dn",rnum);// test park
while(unum != rnum)
{
printf("please enter yours number:");
std::cin >> (unum);
if (unum > rnum)
{
printf("nit is too big!!!n");
}//if
else if(unum < rnum)
{
printf("nit is too smalln");
}// else if
time = time + 1;
}//while in if
printf("you are correct!,you use %d times for finish this gamen",time);
} //if
else if (user == 2)
{
for(int t = 1;t < 6;t++)
{
if(his[t-1] == -1)
{
printf("no datan");
}//if
else{
printf("your game %d is %d timesn",t,his[t-1]);
}//else
}//for
printf("only have 5 size for history, if you play more then 5 times, it will not add inn");
}//else if
else if (user == 3)
{
bk = 1;
}//else if
// printf("time test %dn",time);// test park
//str(time,0);
if (time != 0)
{
his [n]= time;
n = n+1;
}//if
}//while
printf("thanks for play this game, all data will be delete.");
return 0;
}//main
hope to find a idea for how to let user choose delete one of the history, and the next game will save in that which is delete, I try to use number about 1-5 for give user choose which one they want delete, but I have no idea how to after save the new things and going back.For example, game 1 use 2 times, game 2 use 15 times, and user want to delete game 1, after new game game 1 have new data in and how can I let the code read the data start on game 3 not game 2?
coling is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
6