The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
I can't seem to figure put what I'm doing wrong I need to use a switch statement but I can't seem to figure out what I am doing wrong. How do I use a switch statement in my current program I'm trying to figure out. here is my program so far how do I change the if to a switch statement. How do I change the if statements to a switch statement.
Â
Â
#include<iostream>
#include<string>
using namespace std;
string getDay(int);
int main() {
for (int i = 0; i < 9; i++) {
cout << getDay(i) << endl;
}
}
string getDay(int x) {
if (x == 1) {
return "Monday";
}
else if (x == 2) {
return "Tuesday";
}
else if (x == 3) {
return "Wednesday";
}
else if (x == 4) {
return "Thursday";
}
else if (x == 5) {
return "friday";
}
else if (x == 6) {
return "Saturday";
}
else if (x == 7) {
return "Sunday";
}
else {
return "ERROR";
}
}