C++ work 1 switch and while

work

  • switch
#include<iostream>
using namespace std;
int main()
{
	int i;
	cout<<"please enter one member 1 to 7..."<<endl;
	do{
		cin>>i;
		if(i<1||i>7)
		{
			cout<<"input error,out of range...please input again..."<<endl;
		}
	}while(i<1||i>7);
	switch(i)
		{
			case 1:
			case 2:
			case 3:
			case 4:
			case 5:
				cout<<"workday,let's work hard\n"<<endl;break;
			case 6:
			case 7:
				cout<<"weekend,let's have a rest...\n"<<endl;break;
		}
	return 0;
 }   

  • while
#include<iostream>
using namespace std;
int main()
{
	int i;
	int answer=0; 
	cout<<"please input a number "<<endl;
	cin>>i;
	while(i!=0)
	{
		answer*=10;
		answer+=i%10;
		i/=10;
	}
	
	cout<<"answer is "<<answer<<endl;
	
	return 0;
}

posted @ 2018-03-14 20:46  flyingbrid  阅读(160)  评论(0编辑  收藏  举报