学了(混了)一个学期,现在就这样水平(已经用了毕生所学),现在想知道该怎么学了,因为下个星期不学c++了(以后好像都不会上了),下个学期是学数据结构,暑假想提升自己,但不知道从哪里开始,也不知道用什么学(学校教材书太拉了),所以希望给我点帮助
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
class game
{
public:
void menu();
void date();
};
void game::date()
{
int num = 0, gue, i = 0, chance;
srand((unsigned)time(NULL));
num = rand() % 100 + 1;
cout << "请选择你所需要的机会次数" << endl;
cin >> chance;
if(chance>20)
{
cout<<"要这么多机会,还不如直接告诉你答案"<<endl;
cout<<"答案是"<<num<<endl;
}
if (chance < 1)
{
cout << "数据错误,拜拜了 您嘞";
exit(chance = 1);
}
while (1)
{
cout << " 请输入你要猜的数字(1-100): ";
cin >> gue;
if (gue == num)
{
cout << " 恭喜你答对了" << endl;
cout << " 你只用了" << i+1 << "次机会就猜中了" << endl;
break;
}
if (gue < num)
{
cout << " 很遗憾,猜小了 " << endl;
i++;
cout << " 你还剩下 " << chance - i << " 次机会" << endl;
}
if (gue > num)
{
cout << " 很遗憾,猜大了" << endl;
i++;
cout << " 你还剩下 " << chance - i << " 次机会" << endl;
}
if (i == chance)
{
for(int m=0;m<25;m++)
cout << " 失败了,废物" << endl;
cout<<"正确答案是:"<<num<<endl;
break;
}
}
}
void game::menu()
{
cout << " *************************" << endl;
cout << " *************************" << endl;
cout << " *************************" << endl;
cout << " *************************" << endl;
cout << " *******开始游戏请按1*****" << endl;
cout << " *******退出游戏请按0*****" << endl;
cout << " *************************" << endl;
cout << " *************************" << endl;
cout << " *************************" << endl;
cout << " *************************" << endl;
}
int main()
{
int a;int m=1;
game z;
z.menu();
while(m==1)
{
cin>>a;
if(a==0||a==1)
{
switch(a)
{
case 1:
z.date();m=2;
case 0:
m=2;
cout << " bye" << endl;
}
}
else
{
cout<<"数据错误"<<endl;
z.menu() ;
}
}
system("PAUSE");
}