+ 1
How to make a Switch statement in C++
Switch statement of a week https://code.sololearn.com/cHwSZQdPEg5X/?ref=app
15 Antworten
+ 10
#include <iostream>
using namespace std;
int main() {
int day;
cin>>day;
switch(day) {
case 1:
cout <<"Monday";
break;
case 2:
cout <<"Tuesday";
break;
case 3:
cout <<"Wednesday";
break;
case 4:
cout <<"Thursday";
break;
case 5:
cout <<"Friday";
break;
case 6:
cout <<"Saturday";
break;
case 7:
cout <<"Sunday";
break;
}
}
Try this one.
+ 3
#include <iostream>
using namespace std;
int main() {
int day = 7;
switch (day) {
case 6:
cout << "Today is Saturday";
break;
case 7:
cout << "Today is Sunday";
break;
default:
cout << "Looking forward to the Weekend";
}
return 0;
}
+ 3
#include<iostream>
using namespace std;
int main()
{
int a;
cout<<"\n1/2/3"<<endl;
cin>>a;
switch(a)
{
case 1:
cout<<"You pressed 1"<<endl;
break;
case 2:
cout<<"You pressed 2"<<endl;
break;
case 3:
cout<<"You pressed 3"<<endl;
break;
default:
cout<<"Wrong input"<<endl;
break;
}
}
This is how you can do it.
+ 2
Yeah it worked. Thank you.
+ 2
Easy :)
int number;
switch(number){
case 1: cout << "one";
break;
case 2: cout << "two";
break;
default: cout << "zero";
+ 2
#include <iostream>
using namespace std;
int main() {
int num;
string day;
cin>>num;
switch(num) {
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
break;
case 7:
day = "Sunday";
break;
}
cout << day;
return 0;
}
+ 1
Not working. Yes, To make print days as I assign or input values(1,2,3,4)
+ 1
This shows "no output".
https://code.sololearn.com/cUdanCE6Py97/?ref=app
How can i make Switch statement in c++
+ 1
Not working
https://code.sololearn.com/cHwSZQdPEg5X/?ref=app
+ 1
day is the string.
Expected Result:
Inputs a number from 1-7
According to the code 1 prints Monday, 2 prints Tuesday and so on.
In simple words - a c++ program to print days in a week by number using switch statement
+ 1
I declared int day. But it's not still working
+ 1
Ya done it. But it still shows errors
+ 1
How a week can be printed out using Switch statement
+ 1
#include <iostream>
using namespace std;
int main()
{
int a = 12;
switch (a) {
case 18:
cout << "Too young!!";
break;
case 42:
cout << "Adult!!";
break;
case 60:
cout << "Senior!!";
break;
}
return 0;
}
0
Not Possible in C++... Use Java....