In this article you will find tasks, to help you master the basic skills to use in their programs the statement multiple choiceswitch. I read about this in the article can be The switch statement in C ++. Most requested – try first to solve the task yourself and then either sneak peek (If so and it did not work), or compare your decision with the, what is set out here. Let's go!
1. Create a schedule for the week. The user enters a numeric representation of the day of the week and it is displayed on the screen, then, which is scheduled for this day.
2. Change code, which was considered in the articleThe switch statement in C ++, in the following way: The user to calculate the travel time does not need to enter station numbers, and the letters(A,B,C,D,E). You must provide user input and small, and large letters (get rid of the case-sensitive). That is, if you have entered or D, or d – should work the same case. The syntax for this action is the:
switch (expression)
{
case ‘a’:
case ‘A’: //code
break;
etc. …………….
}
Another task can be viewed at this article. For all questions, leave a comment below the article.
interesting tasks! If there were more
Thanks! I hope, This is not a very difficult task to help me master the basic skills used in applications of statement multiple choice switch. I really have more examples of such tasks)))) Always easier to learn new material, many examples where.
Interestingly enough, all painted, with comments, really easy to master statement Switch, even just repeat to yourself like that! Thanks to the author!
#include “stdafx.h”
#include
#include
#include
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(LC_ALL, “rus”);
using namespace std;
string a, b, c, d, e, f, g;
int day;
cout <> a ;
cout <> b ;
cout <> c ;
cout <> d ;
cout <> e ;
cout <> f ;
cout <> g ;
cout <> day;
switch (day)
{
case 1:
cout << a << endl;
break;
case 2:
cout << b << endl;
break;
case 3:
cout << c << endl;
break;
case 4:
cout << d << endl;
break;
case 5:
cout << e << endl;
break;
case 6:
cout << f << endl;
break;
case 7:
cout << g << endl;
break;
default:
cout << "Неправильное число!";
}
_getch();
}
not so easy ?
#include “stdafx.h”
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
setlocale (0,””);
char metro;
cout << " For year nažminete (0)." ;
cout <<endl<<endl;
cout <> metro;
cout <<endl<<endl;
switch (metro)
{
case '0' : cout << " Exit " <<endl ;break;
case 'a':
case 'A': cout << " Anino Metro Station / Orange branch / " <<endl; break;
case 'b':
case 'B': cout << " Metro station Brno / blue branch / " <<endl; break;
default :
cout << " there is no such station! " <<endl;
}
}while (metro != '0');
cout <<endl;
return 0;
}
And how do you know for this code, a user has selected day?
It is not clear why the cycle used in the second problem, because after the first withdrawal of the program shuts down.
sorry, all clear