c++学习3

1.重复验证账号密码直到输入正确打印出菜单

int main(void) {
	string username;//账号
	string password;//密码

	while (true) {//账号或密码错误就重复输入
		system("cls");
		cout << "请输入账号:";
		cin >> username;
		cout << "请输入密码:";
		cin >> password;
		if (username == "magic007" && password == "123456") {//判断账号密码
			system("cls");//清除控制台
			break;
		}
		else {
			cout << "账号或者密码错误!" << endl;
			system("pause");
		}
	}
	cout << "网站404攻击" << endl;
	cout << "网站篡改攻击" << endl;
	cout << "网站攻击记录" << endl;
	cout << "DNS攻击" << endl;
	cout << "服务器重启攻击" << endl;
	
	system("pause");
	return 0;
}

清除控制台   system("cls");

2.1加到100

#include <iostream>
#include <Windows.h>
#include <string>
#define endNum 100//1加到的第n个数

using namespace std;

int main(void) {
	int i = 1;
	int sum = 0;
	while (i <= endNum){
		sum += i;//总和
		i++;
	}
	cout << "1+" << endNum << "=" << sum << endl;

	system("pause");
	return 0;
}

3.continue用法

#include <iostream>
#include <Windows.h>
#include <string>

using namespace std;

int main(void) {
	string answer;//女主回答

	for (int i = 1; i <= 3; i++) {//三次相亲
		cout << "第" << i << "次相亲" << endl;
		cout << "你喜欢打王者吗?" << endl;
		cin >> answer;
		if (answer != "yes")//判断兴趣是否相同
		{
			system("pause");
			system("cls");
			continue;
		}
		else {
			cout << "加个微信吧!" << endl;
			system("pause");
			system("cls");
		}

	}

	system("pause");
	return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值