1.读取键盘输入
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
int main()
{
char ch=0;
cout<<"Please enter:";
while((ch=cin.get())!='@')
{
if(isdigit(ch))
{
continue;
}
else if (islower(ch))
{
cout<<(char)toupper(ch);
}
else if (isupper(ch))
{
cout << (char)tolower(ch)<<endl;;
}
}
cout << "Ending" << endl;
return 0;
}
2.存十个数值
#include "stdafx.h"
#include<iostream>
#include<string>
#include<array>
using namespace std;
const unsigned int SIZE=10;
int main()
{
array<double,SIZE> donation;
int enter=0;
double total_value=0.0;
double avg=0.0;
int over_avg=0;
cout<<"Please enter ten doulbe value(Non-numeric to exit):";
while(enter<10&&(cin>>donation[enter]))
{
total_value+=donation[enter];
enter++;
}
avg=total_value/enter;
for(int i=0;i<enter;i++)
{
if(donation[i]>avg)
{
over_avg++;
}
}
cout<<"The average value is "<<avg<<",and there are "<<over_avg
<<" double value more than average !"<<endl;
return 0;
}
3.菜单驱动程序
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
int main()
{
char ch=0;
cout<<"Please enter one of the following choices:\n"
"c) carnivore p)pianist \n"
"t) tree g)game\n";
while(cin>>ch)
{
switch(ch)
{
case 'c':
cout<<"carnivore"<<endl;
break;
case 'p':
cout << "pianist" <<