📄 loop.cpp
字号:
//using a nested loop to generate mutiplication tables
//just to fun!
#include<iostream>
#include<iomanip>
#include<cctype>
#include<ctime>
#include<windows.h>
using namespace std;
int main(){
const int len_max=12;
const int wid_max=12;
int tab_len,tab_wid;
char reply;
int count=1;
int i;
do{
cout<<"please input the length"<<"(0-"
<<len_max<<")"<<endl;
cin>>tab_len;
cout<<"please input the width"<<"(0-"
<<wid_max<<")"<<endl;
cin>>tab_wid;
if(tab_len>len_max||tab_wid>wid_max){
cout<<"Invalid input."<<endl;
cout<<endl<<"Do you want to continue?"<<endl;
cin>>reply;
if(reply=='y')
{
count++;
continue;
}
else
break;
}
cout<<" ";
for(i=1;i<=tab_len;i++)
cout<<setw(5)<<i;
cout<<endl;
for(i=1;i<=tab_len;i++)
cout<<"------";
cout<<endl;
for(i=1;i<=tab_wid;i++)
{
cout<<setw(2)<<i<<'|'<<' ';
for(int j=1;j<=tab_len;j++)
cout<<setw(5)<<i*j;
cout<<endl;
}
cout<<"Do you want to generate another one?('y'or'Y')"<<endl;
cin>>reply;
}while(tolower(reply)=='y'&&count<=3);
if(count=3)
cout<<"Sorry! You have tried for 3 times!"<<endl;
char*pStr= " ┃ \n"
" ┃ \n"
" ┏━━━━┻━━━━┓ \n"
" ┃ 关于作者 ┃ \n"
" ┏━━━━┻━━━━━━━━━┻━━━━┓\n"
" ┃ ┃\n"
" ┃ Aauthor: ┃\n"
" ┃ QQ: ┃\n"
" ┃ E-mail: ┃\n"
" ┃ ┃\n"
" ┗━━━━━━━━━━━━━━━━━━━┛\n";
system("cls");
srand(time(0));
for(i=0; i<strlen(pStr); i++)
{
if(pStr[i]!=' ')
{
Sleep(20);
}
cout<<pStr[i];
}
cout<<endl<<endl<<endl<<endl;
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -