猜数小游戏

这是一个使用C++编写的猜数小游戏,包括不同难度级别,如1到10、1到100等。游戏会根据玩家猜测次数计算得分,并通过控制台交互进行反馈。玩家可以选择是否继续游戏。
摘要由CSDN通过智能技术生成

#include<bits/stdc++.h>

#include<windows.h>

#include <conio.h> 
             
using namespace std;

float score(int i, int sum)
{
    switch (i)
    {

        case 1:    
        
        return i * 20 + 1.0 / sum * 80; 

        break;

        case 2:
            
        return i * 20 + 1.0 / sum * 90; 

        break;

        case 3:
            
        return i * 25 + 1.0 / sum * 70; 

        break;
        
        case 4:
        
        return i * 30 + 1.0 / sum * 60; 
        
        break;
        
        case 5:
        
        return i * 35 + 1.0 / sum * 50; 
        
        break;
        
        case 6:
        
        return i * 40 + 1.0 / sum * 40; 
        
        break;

    }
}
void Slowsay(string a) 

    int l = a.size(); 
    
    for(int i = 0;i < l;i++)
    {
        cout<<a[i]; 
         
        Sleep(30);   
    }
    
    printf("\n");   

int f(int a)
{
    if(a == 1)
    {
        int b = rand() % 10 + 1; 
        
        int c; 
        
        int d = 0; 
        
        Slowsay("开始!"); 
        
        while(cin>>c)
        {
            if(c < b)
            {
                Slowsay("猜小了"); 
                
                d++;  
            }
            if(c > b)
            {
                Slowsay("猜大了"); 
                
                d++; 
            }
            if(c == b)
            {
                Slowsay("恭喜你,猜对了!"); 
                
                d++; 
                
                cout<<"你一共猜了"<<d<<"次 "<<endl; 
                
                cout<<"你的分数是:"<<score(a,d)<<endl; 
                
                system("pause");
                
  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值