Guess the word game and shut down, you can also fix your friends.

Guess the word + shutdown

Novice friends often feel boring and humble in the learning process. Why do others have so many tips! Why do they know so much about me!
What a coincidence! The blogger, as a little rookie, thinks the same way. Hahahaha! In fact, these are learned slowly. Quietly tell you that the blogger will also be this one..., even though I will post, because I also want you to know. Enrich yourself.
First of all, everyone should know such a few little knowledge (don't tell others!)
1.rand(); is a sentence that generates random numbers, but you don't believe it every time, try the following sentence.

#include <stdio.h>
int main ()
{
    
    
	int a;
	a=rand();
	printf("%d",a);
	return 0;
}

The real statement is srand((unsigned)time(NULL)); when using this statement, don't forget to add #include<time.h>. Here because srand() is used to initialize the random seed number, it is allocated by time, so as long as the value of time changes, the value it generates will also change. But have you found that the values ​​you generate are too big, it doesn’t matter you just do this (see code)

srand((unsigned)time(NULL));
a=rand()%100;

Well, you know the basic knowledge. So let's get started.

#include <stdio.h>
#include <stdlib.h>//这个不能丢
#include <time.h>
int main()
{
    
    
	int a,sum,b;
	sum=6;//可以设置你想要次数
	srand((unsigned)time(NULL));//必须记住
	a=rand()%100;
	while(1)
	{
    
    
		sum--;
		scanf("%d",&b);
		if(b<a)
			printf("小了,还剩%d次机会,请继续\n",sum);
		if(b>a)
			printf("大了,还剩%d次机会,请继续\n",sum);
		if(b==a)
		{
    
    	printf("针不戳,666\n");
			break;
		}
		if(sum==0)
		{
    
    
			printf("你挺菜的啊\n");
			break;
		}
	}
	return 0;
}

2. Shutdown command system ("shutdown -s -t 50"); If you want to show, you must remember. 50 Here you can adjust the shutdown time. Do not believe? ? ? Then you try the following code

#include <stdio.h>
#include <stdlib.h>
int main()
{
    
    
	system("shutdown -s -t 50");
	return 0;
}

hahahaha how is it true? Below, you only need to combine the word guessing game above, and you will be able to use a program with a lost bull.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
    
    
	int a,sum,b;
	sum=6;
	srand((unsigned)time(NULL));
	a=rand()%100;
	while(1)
	{
    
    
		sum--;
		scanf("%d",&b);
		if(b<a)
			printf("小了,还剩%d次机会,请继续\n",sum);
		if(b>a)
			printf("大了,还剩%d次机会,请继续\n",sum);
		if(b==a)
		{
    
    	printf("真不错,666\n");
			break;
		}
		if(sum==0)
		{
    
    
			printf("很遗憾,没机会了\n");
			system("shutdown -s -t 50");//没错就只要加个这个语句。
			break;
		}
	}
	return 0;
}

By the way, system("shutdown -a"); is an instruction to cancel shutdown.
If you learn it, go and make fun of others, hehehe!
Remember that we who learn programs are always rookies, don't be self-righteous, and learn slowly like me.
Welcome everyone to make suggestions to rookie bloggers, thank you!

Guess you like

Origin blog.csdn.net/m0_52699073/article/details/110431053