C++好玩程序合集

好玩的C++程序合集

        哈喽大家好啊,本文为大家整理了很多好玩的C++程序

        今天这个合集的代码非常简单,初学者也可以看懂!(如2、3都是小编原创啊

        我们来一个一个看。

1.乱飞的鼠标

        几行代码就能实现啦!

        这个可以用来坑别人,措手不及!让鼠标不受控制。(Alt+F4关闭程序

#include<bits/stdc++.h>
#include<windows.h>
#include<ctime>
using namespace std;
int main()
{
    int x=GetSystemMetrics(SM_CXSCREEN);   //设置鼠标x坐标
    int y=GetSystemMetrics(SM_CYSCREEN);   //鼠标的y坐标
    srand(time(0));
    while(1)     //死循环
    SetCursorPos(rand()%x,rand()%y);    //设置鼠标在随机坐标
    return 0;
}
//————————————————
//作者:Hacker Pig
//在csdn

2.风火轮

        知识点:\b回退

        使用\b来实现风火轮的动画。

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main()
{
	for(;;){   //无限循环
        cout<<'\b'<< '-';
        Sleep(50);     //等50毫秒
        cout<<'\b'<<'\\';  //输出'\'字符时需要用转换描述形式写成'\\'
        Sleep(50);
        cout<<'\b'<<'/';
        Sleep(50);
    }
    return 0;
}
//作者:Hacker Pig 在csdn

3.石头剪刀布

1=石头

2=剪刀

3=布!

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a==1&&b==2||a==2&&b==3||a==3&&b==1)
	    cout<<"win";
	else if(a==b)
	    cout<<"tie";
	else
	    cout<<"lose";
	return 0;
}
//1、2、3,分别代表石头、剪刀、布!
//作者:Hacker Pig
//在csdn

好啦,这篇文章就说到这里啦。拜拜!

大家还感兴趣什么话题呢?欢迎评论

———————————————————————————————————————————

作者编辑不易,除代码外请不要转载哦---

  • 8
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Dev-C++是一个免费的C/C++集成开发环境(IDE),它可以帮助程序员编写、编译、调试和运行C/C++程序。以下是一些有趣的Dev-C++代码示例: 1. 猜数字游戏 这是一个简单的猜数字游戏,程序会随机生成一个1到100之间的数字,玩家需要猜出这个数字是多少。 ```c++ #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(0)); // 设置随机数种子 int number = rand() % 100 + 1; // 生成1到100之间的随机数 int guess; int tries = 0; do { cout << "Guess a number between 1 and 100: "; cin >> guess; tries++; if (guess > number) { cout << "Too high!" << endl; } else if (guess < number) { cout << "Too low!" << endl; } else { cout << "You win!" << endl; cout << "Number of tries: " << tries << endl; } } while (guess != number); return 0; } ``` 2. 打印九九乘法表 这个程序可以打印出九九乘法表。 ```c++ #include <iostream> using namespace std; int main() { for (int i = 1; i <= 9; i++) { for (int j = 1; j <= i; j++) { cout << j << " x " << i << " = " << i * j << "\t"; } cout << endl; } return 0; } ``` 3. 简单的计算器 这个程序可以实现简单的加、减、乘、除运算。 ```c++ #include <iostream> using namespace std; int main() { char op; double num1, num2; cout << "Enter operator (+, -, *, /): "; cin >> op; cout << "Enter two numbers: "; cin >> num1 >> num2; switch(op) { case '+': cout << num1 + num2; break; case '-': cout << num1 - num2; break; case '*': cout << num1 * num2; break; case '/': if (num2 == 0) { cout << "Error: division by zero"; } else { cout << num1 / num2; } break; default: cout << "Error: invalid operator"; break; } return 0; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值