猜数字游戏 DevC++

算法打基础之猜数字小游戏

#include <stdio.h>

int main()
{	
	int oldprice,price = 0,i = 0;
	printf("请首先设置商品的真实价格:");
	scanf("%d",&oldprice);
	system("cls");
	printf("请输入试猜的价格:\n");
	while(oldprice != price)
	{
		i++;
		printf("参与者:");
		scanf("%d",&price);
		printf("主持人:");
		if(price > oldprice)
		{
			printf("高了\n");
		} 
		else if(price < oldprice)
		{
			printf("低了\n");
		}
		else 
		{
			printf("恭喜你,答对了,该商品属于你了!\n\n 你一共试错了%d 次", i);
		} 
    }
	getch();
	return 0; 
} 
发布了24 篇原创文章 · 获赞 5 · 访问量 2776

猜你喜欢

转载自blog.csdn.net/m0_37536859/article/details/104256764
今日推荐