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
"<<endl;break;
			case 6:
			case 7:
				cout<<"weekend,let's have a rest...
"<<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;
}

原文地址:https://www.cnblogs.com/flyingbrid-nest/p/8569972.html