homework 12.14

This commit is contained in:
Dengrb 2024-12-13 21:59:52 +08:00
parent 6d0e343276
commit 5af1eb3a4e

72
homework.cpp Normal file
View File

@ -0,0 +1,72 @@
#include<iostream>
#include<windows.h>
using namespace std;
void while_on();
void while_off();
int main(){
cout <<"请选择"<<endl;
cout <<"1.不带循环版"<<endl<<"2.带循环版"<<endl<<"3.退出"<<endl;
cout <<">>>";
int count;
cin >>count;
if (count == 1)
{
while_off();
}else if (count == 2)
{
while_on();
}else if (count == 3)
{
return 0;
}else
{
cout <<"无效的选择!"<<endl;
Sleep(1850);
return 1;
}
return 0;
}
void while_off(){
cout <<"现在模式是 不带循环版"<<endl;
Sleep(1250);
cout <<"请输入一个正整数:";
int num;
cin >>num;
int count1 = 0;
while (num > 0)
{
num /= 10;
count1++;
}
cout <<count1<<endl;
Sleep(2000);
}
void while_on(){
cout <<"现在模式是 带循环版"<<endl;
Sleep(1250);
while (TRUE)
{
cout <<"请输入一个正整数:";
int num;
cin >>num;
int count2 = 0;
while (num > 0)
{
num /= 10;
count2++;
}
cout <<count2<<endl;
Sleep(2000);
}
}