0
点赞
收藏
分享

微信扫一扫

猜数字游戏【C语言】

后来的六六 2022-03-18 阅读 92
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(){
	int times;
	int number;
	
	int randValue;
	srand(time(NULL));
	randValue=1+(int)rand()%100;
	
	printf("Enter a number:\n");
	for(times=1; times<=7; times++){
		scanf("%d", &number);
		if(number<randValue){
			printf("Wrong Number, Try Again\n");
			if(times==7){
				printf("Sorry, you lose\n");
			}
		}
		else if(number>randValue){
			printf("Wrong Number, Try Again\n");
		}
		else if(number==randValue){
			printf("Hooray, You have won!");
			break;
		}
	}

	return 0;
}
举报

相关推荐

0 条评论