初学C++的代码,请大家指点里面的不足之处,谢谢了 !
#include <iostream>
#include <string>
using namespace std;
int i=1;
double d = 11.12;
float f = 123.1;
char c = 'a';
string s = "leelnxxiang";
//long l = 123.2;
//short sh = 123123.123;
bool boo = 1;
void for_dir()
{
for(int i=0;i<100;i++)
{
cout << i;
cout << endl;
}
}
void arrays()
{
int id[100];
for(int i=0;i<100;i++)
{
id[i] = i;
cout << "id[" << id[i] << "]";
cout << endl;
}
}
void arrays_char()
{
cout << "请输入您的名字................................";
cout << endl;
char ch[11];
string str = "" ;
for(int i=0;i<11;i++)
{
cin >> ch[i];
str += ch[i];
}
cout <<"您输入的是: " << str;
}
void while_dir()
{
int x=1;
while(true)
{
cout << endl;
cout << "while ing ............" << x;
x++;
if(x == 33)
{
return;
}
}
}
void do_dir()
{
int x = 1;
do
{
cout << endl;
cout << "do while ing ............" << x;
x++;
if(x == 33)
{
return;
}
}
while(true);
}
void exit_exit()
{
cout << "退出程序请输入 'exit' ...........";
cout << endl;
string s = "";
cin >> s;
if(s == "exit")
{
cout << "保存退出程序成功!";
exit(0);
}
else
{
cout << "输入错误,程序将不保存运行";
}
}
void display()
{
cout << i;cout << endl;
cout << d;cout << endl;
cout << f;cout << endl;
cout << c;cout << endl;
cout << s;cout << endl;
//cout << l;cout << endl;
//cout << sh;cout << endl;
cout << boo;cout << endl;
}
void Cf()
{
for(int i=1;i<10;i++)
{
for(int j=1;i>=j;j++)
{
cout << i << "*" << j << "=" << i*j << " ";
}
cout << endl;
}
}
int main()
{
cout << "hello world";
cout << endl;
cout << "for .....................";
cout <<endl;
for_dir();
cout << endl;
cout << "while ...................";
while_dir();
cout << endl;
cout << "do ..................................";
do_dir();
cout << endl;
printf("显示乘法口诀..................");
cout << endl;
Cf();
printf("显示数据类型..................");
cout << endl;
display();
cout << endl;
arrays();
arrays_char();
cout << endl;
exit_exit();
}