求助!c++初学者问题!

来源:百度知道 编辑:UC知道 时间:2024/05/26 14:46:00
题是这样的:

写一个程序,一开始它会要求使用者输入一个从1到10的整数,在它的内部有一个默认值,程序会根据使用者的输入值提示“太大”,“太小”等信息,直到使用者猜中为止。

#include <iostream.h>
void main()
{
int N;
int D = 3;
do
{

cout << "请输入一个从1到10的整数" << endl;
cin >> N >> endl;
if ((N <=1) || (N >=10 ))
cout << "超出范围!" << endl;
else
if (N < 3)
cout << "太小" << endl;
else if (N > 3)
cout << "太大" << endl;
}

while (N == D );
cout << "对了" << endl;
}

编译出了问题,error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class ostream &(__cdecl *)(class ostream &)' (or there is no acceptable conversion)。

----------
请问我写的程序都有什么问题啊。
先谢过

你一看提示应该就明白:">>"后面是不应该加"endl"的

#include <iostream.h>
void main()
{
int N;
int D = 3;
do
{

cout << "请输入一个从1到10的整数" << endl;
cin >> N >> endl;
if ((N <=1) || (N >=10 ))
cout << "超出范围!" << endl;
else
if (N < 3)
cout << "太小" << endl;
else
cout << "太大" << endl;
}

while (N == D );
cout << "对了" << endl;
}

c++中没有else if 语句。