24.定义一个整型变量,赋予1-100值。要求用户猜这个数,比较两数大小,把结果提示给用户,直到猜对为止
2014-08-06 16:43
477 查看
#include<iostream> using namespace std; int main() { int a=50; int n; while(1)//关键,造成一个死循环 { cout<<"please input an number: "<<endl; cin>>n; if(a==n)//循环退出条件 { cout<<"n="<<n<<endl; break; }else if(a<n) { cout<<"your number are biger than the number,please try again."<<endl; }else if(a>n) { cout<<"your number are smaller than the number,please try again."<<endl; } } return 0; }
相关文章推荐
- 定义一个整型变量赋予1~100的值,要求用户猜这个数,并把结果提示给用户直到猜对为止。
- 定义一个变量,赋予1~100的值,让用户猜值,比较大小,直到猜对位置
- 用两个线程玩猜数字游戏,第一个线程负责随机给出1~100之间的一个整数,第二个线程负责猜出这个数。要求每当第二个线程给出自己的猜测后,第一个线程都会提示“猜小了”、“猜大了”或“猜对了”。猜数之前,要
- 用两个线程玩猜数字游戏,第一个线程负责随机给出1~100之间的一个整数,第二个线程负责猜出这个数。要求每当第二个线程给出自己的猜测后,第一个线程都会提示“猜小了”、“猜大了”或“猜对
- 产生一个1--10之间的随机数,用户去猜这个数,直到猜中为止
- 用两个线程玩猜数字游戏,第一个线程负责随机给出1~100之间的一个整数,第二个线程负责猜出这个数。要求每当第二个线程给出自己的猜测后,第一个线程都会提示“猜小了”、“猜大了”或“猜对
- 用两个线程玩猜数字游戏,第一个线程负责随机给出1~100之间的一个整数,第二个线程负责猜出这个数。要求每当第二个线程给出自己的猜测后,第一个线程都会提示“猜小了”、“猜大了”或“猜对
- lesson 10:用两个线程玩猜数字游戏,第一个线程负责随机给出1~100之间的一个整数,第二个线程负责猜出这个数。要求每当第二个线程给出自己的猜测后,第一个线程都会提示“猜小了”、“猜大了”或“猜
- 用两个线程玩猜数字游戏,第一个线程负责随机给出1~100之间的一个整数,第二个线程负责猜出这个数。要求每当第二个线程给出自己的猜测后,第一个线程都会提示“猜小了”、“猜大了”或“猜对了”。猜数之前,要
- 编写一个程序,要求输入两个浮点数,然后打印出用二者的差值除以二者的乘积所得的结果。在用户非数字的输入之前程序循环处理输入值。
- 请定义一个宏,比较两个数a、b的大小,不能使用大于、小于、if语句
- 有一个长度为n(n<=100)的数列,该数列定义为从2开始的递增有序偶数(2,4,6,8,10,…),现在要求你按照顺序每m个数求出一个平均值,如果最后不足m个,则以实际数量求平均值。编程输出该平均值
- 请定义一个宏,比较两个数的a、b的大小,不能使用大于、小于、if语句
- [转]给你一个单词a,如果通过交换单词中字母的顺序可以得到另外的单词b,那么定义b是a的兄弟单词。现在给你一个字典,用户输入一个单词,让你根据字典找出这个单词有多少个兄弟单词
- C++ 计算一个线段长度,两个端点的坐标值分别为(100,200)(200,300)。要求:定义一个CLine类,属性是CPoint对象。(初始化参数列表)
- 8.不断 要求用户输入一个数字,然后打印这个数字的二倍,当用户输入q的时候程序退出(return)
- 实现一个"可变二维数组",这个二维数组的行数要求用户从键盘输入,每行的元素个数仍由用户从键盘输入. //数组元素值用户可以自定义.最后把二维数组打印出来.不要忘记释放数组内存. /*void main
- Problem Description 有一个长度为n(n<=100)的数列,该数列定义为从2开始的递增有序偶数,现在要求你按照顺序每m个数求出一个平均值,如果最后不足m个,则以实际数量求平均值。编程输出该平均值序列。 Input 输入数据有多组,每组占一行,包含两个正整数n和m,n和m的含义
- 定义一个宏,比较a和b的大小,不用大于,小于,if语句
- 请定义一个宏,比较两个数a、b的大小,不能使用大于、小于、if语句。