Please Help: Switch Case

the output works correctly but every time it puts the name of the month theres a set of the same digits that follow it. How do I get it to just put the name of the month without the digits?




#include <iostream>
#include <iomanip>

using namespace std;

/* Function Prototype */
int NameMonth (int Month);


/* Main Program */
int main()
{
int Month, NameOfMonth;


cout << "Enter the Month (by number 1-12): ";
cin >> Month;

cout << setprecision(2) << fixed;

cout << NameMonth (Month);
cout<< setw(6) << "Sun"
<< setw(6) << "Mon"
<< setw(6) << "Tues"
<< setw(6) << "Wed"
<< setw(8) << "Thurs"
<< setw(6) << "Fri"
<< setw(6) << "Sat"
<< endl;
}

int NameMonth (int Month)
{
switch (Month){
case 1 : cout << "January" << endl ; break;
case 2 : cout << "Feburary" << endl ; break;
case 3 : cout << "March" << endl ; break;
case 4 : cout << "April" << endl ; break;
case 5 : cout << "May" << endl ; break;
case 6 : cout << "June" << endl ; break;
case 7 : cout << "July" << endl ; break;
case 8 : cout << "August" << endl ; break;
case 9 : cout << "September"<< endl ; break;
case 10: cout << "October" << endl ; break;
case 11: cout << "November" << endl ; break;
case 12: cout << "December" << endl ; break;
default : cout << "0";
}
}


Last edited on
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

/* Function Prototype */
string NameMonth (int );


/* Main Program */
int main()
{
   int Month, NameOfMonth;


   cout << "Enter the Month (by number 1-12): ";
   cin >> Month;

   cout << setprecision(2) << fixed;

   cout << NameMonth (Month);
   cout<< setw(6) << "Sun"
    << setw(6) << "Mon"
    << setw(6) << "Tues"
    << setw(6) << "Wed"
    << setw(8) << "Thurs"
    << setw(6) << "Fri"
    << setw(6) << "Sat"
    << endl;
}

string NameMonth (int Month)
{
   switch (Month){
   case 1 : return "January"; break;
   case 2 : return "February"; break;
   case 3 : return "March"; break;
   case 4 : return "April"; break;
   case 5 : return "May"; break;
   case 6 : return "June"; break;
   case 7 : return "July"; break;
   case 8 : return "August"; break;
   case 9 : return "September"; break;
   case 10: return "October"; break;
   case 11: return "November"; break;
   case 12: return "December"; break;
   default : return "** Invalid month number **";
 }
}
Last edited on
Topic archived. No new replies allowed.