+ 1

How to make a Switch statement in C++

Switch statement of a week https://code.sololearn.com/cHwSZQdPEg5X/?ref=app

26th Aug 2022, 10:44 AM
Pro Coder
Pro Coder - avatar
23 Respostas
+ 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.
26th Aug 2022, 1:30 PM
Ashutosh Deshmukh
+ 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; }
26th Aug 2022, 12:53 PM
Harsh Nama
Harsh Nama - avatar
+ 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.
26th Aug 2022, 1:20 PM
Ashutosh Deshmukh
+ 2
Yeah it worked. Thank you.
26th Aug 2022, 1:32 PM
Pro Coder
Pro Coder - avatar
+ 2
Easy :) int number; switch(number){ case 1: cout << "one"; break; case 2: cout << "two"; break; default: cout << "zero";
26th Aug 2022, 9:14 PM
Amirroox
Amirroox - avatar
+ 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; }
27th Aug 2022, 11:50 AM
TeaserCode
+ 1
Not working. Yes, To make print days as I assign or input values(1,2,3,4)
26th Aug 2022, 10:53 AM
Pro Coder
Pro Coder - avatar
+ 1
This shows "no output". https://code.sololearn.com/cUdanCE6Py97/?ref=app How can i make Switch statement in c++
26th Aug 2022, 11:14 AM
Pro Coder
Pro Coder - avatar
26th Aug 2022, 11:32 AM
Pro Coder
Pro Coder - avatar
+ 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
26th Aug 2022, 11:37 AM
Pro Coder
Pro Coder - avatar
+ 1
I declared int day. But it's not still working
26th Aug 2022, 11:49 AM
Pro Coder
Pro Coder - avatar
+ 1
Ya done it. But it still shows errors
26th Aug 2022, 11:52 AM
Pro Coder
Pro Coder - avatar
+ 1
How a week can be printed out using Switch statement
26th Aug 2022, 1:24 PM
Pro Coder
Pro Coder - avatar
+ 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; }
26th Aug 2022, 2:36 PM
ㅀㅀㅀㅀ Pràž„àž‡Ä“Ćžh ƞiàș–àș‡h Pàž„tēl 🎃
ㅀㅀㅀㅀ Pràž„àž‡Ä“Ćžh ƞiàș–àș‡h Pàž„tēl 🎃 - avatar
0
Not Possible in C++... Use Java....
26th Aug 2022, 10:57 AM
Aman Kumar Sinha
Aman Kumar Sinha - avatar