zoukankan      html  css  js  c++  java
  • 利用switch语句编写猜数字(1~10)小游戏

    #include <iostream>
    
    using namespace std;
    
    int main()
    
    {
    
           int a,b,c,d,e,f,j,h,i,g;
    
           cout<<"下面我们做一个小游戏"<<endl;
    
           cout<<"请您每次任意输入1~10的一个数字,按回车键"<<endl;
    
           cout<<"我们为你准备了一个幸运数字"<<endl;
    
        cin>>a;
    
           switch(a)
    
           {
    
           case 1:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 2:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 3:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 4:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 5:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 6:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 7:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 8:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 9:cout<<"哇,你真是天才,恭喜你猜对啦!"<<endl;break;
    
        case 10:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           default :cout<<" sorry you are wrong"<<endl;break;
    
           }
    
        cin>>b;
    
           switch(b)
    
           {
    
           case 1:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 2:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 3:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 4:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 5:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 6:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 7:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 8:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 9:cout<<"哇,你真是天才,恭喜你猜对啦!"<<endl;break;
    
        case 10:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           default :cout<<" sorry you are wrong"<<endl;break;
    
           }
    
        cin>>c;
    
           switch(c)
    
           {
    
           case 1:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 2:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 3:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 4:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 5:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 6:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 7:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 8:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 9:cout<<"哇,你真是天才,恭喜你猜对啦!"<<endl;break;
    
        case 10:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           default :cout<<" sorry you are wrong"<<endl;break;
    
           }
    
        cin>>d;
    
           switch(d)
    
           {
    
           case 1:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 2:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 3:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 4:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 5:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 6:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 7:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 8:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 9:cout<<"哇,你真是天才,恭喜你猜对啦!"<<endl;break;
    
        case 10:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           default :cout<<" sorry you are wrong"<<endl;break;
    
           }
    
        cin>>e;
    
           switch(e)
    
           {
    
           case 1:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 2:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 3:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 4:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 5:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 6:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 7:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 8:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 9:cout<<"哇,你真是天才,恭喜你猜对啦!"<<endl;break;
    
        case 10:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           default :cout<<" sorry you are wrong"<<endl;break;
    
           }
    
        cin>>f;
    
           switch(f)
    
           {
    
           case 1:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 2:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 3:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 4:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 5:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 6:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 7:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 8:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 9:cout<<"哇,你真是天才,恭喜你猜对啦!"<<endl;break;
    
        case 10:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           default :cout<<" sorry you are wrong"<<endl;break;
    
           }
    
        cin>>j;
    
           switch(j)
    
           {
    
           case 1:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 2:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 3:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 4:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 5:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 6:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 7:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 8:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 9:cout<<"哇,你真是天才,恭喜你猜对啦!"<<endl;break;
    
        case 10:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           default :cout<<" sorry you are wrong"<<endl;break;
    
           }
    
        cin>>h;
    
           switch(h)
    
           {
    
           case 1:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 2:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 3:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 4:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 5:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 6:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 7:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 8:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 9:cout<<"哇,你真是天才,恭喜你猜对啦!"<<endl;break;
    
        case 10:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           default :cout<<" sorry you are wrong"<<endl;break;
    
           }
    
        cin>>i;
    
           switch(i)
    
           {
    
           case 1:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 2:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 3:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 4:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 5:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 6:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 7:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 8:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 9:cout<<"哇,你真是天才,恭喜你猜对啦!"<<endl;break;
    
        case 10:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           default :cout<<" sorry you are wrong"<<endl;break;
    
           }
    
        cin>>g;
    
           switch(g)
    
           {
    
           case 1:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 2:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           case 3:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 4:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 5:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 6:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 7:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 8:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
        case 9:cout<<"哇,你真是天才,恭喜你猜对啦!"<<endl;break;
    
        case 10:cout<<"很抱歉,您猜错了,再试一次"<<endl;break;
    
           default :cout<<" sorry you are wrong"<<endl;break;
    
           }
    
        return 0;
    
    }
    
    

  • 相关阅读:
    Codeforces Round #620 (Div. 2)
    Codeforces Round #575 (Div. 3)
    Codeforces Round #619 (Div. 2)
    2014 Nordic Collegiate Programming Contest
    Educational Codeforces Round 82 (Rated for Div. 2)
    模板
    2015-2016 ACM-ICPC Southwestern Europe Regional Contest (SWERC 15)
    模板
    Codeforces Round #618 (Div. 2)
    Codeforces Round #343 (Div. 2)
  • 原文地址:https://www.cnblogs.com/sr1993/p/3697892.html
Copyright © 2011-2022 走看看