if.cpp

#include<iostream>
using namespace std;
int main()
{
char ch;
int spaces=0;
int total=0;
cin.get(ch);
while (ch!='.')
{
if (ch==' ')
++spaces;
++total;
cin.get(ch);
}
cout<<spaces<<" spaces,"<<total;
cout<<" characters total in sentence\n";

system("pause");
return 0;
}

ifelse.cpp

#include<iostream>
using namespace std;
int main()
{
char ch;
cout<<"Type,and I shall repeat.\n";
cin.get(ch);
while (ch!='.')
{
if (ch=='\n')
cout<<ch;
else
cout<<++ch;
cin.get(ch);
}

cout<<"\nPlease excuse the slight confusion,\n";
//cin.get();
//cin.get();

system("pause");
return 0;
}

ifelseif.cpp

#include<iostream>
using namespace std;
const int Fave=27;
int main()
{
int n;
cout<<"Enter a number in the range 1-100 to find ";
cout<<"my favorite number:";
do
{
cin>>n;
if (n<Fave)
cout<<"Too low -- guess again:";
else if (n>Fave)
cout<<"Too high -- guess again:";
else
cout<<Fave<<" is right!\n";
}while (n!=Fave);

system("pause");
return 0;
}

 posted on 2021-04-17 22:03  HuJiao粉  阅读(57)  评论(0)    收藏  举报