GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Oct-2009, 03:47
saqib_ saqib_ is offline
New Member
 
Join Date: Oct 2009
Posts: 12
saqib_ has a little shameless behaviour in the past

The switch statement is not working


The following code gives the out put in the correct manner but without the month being in english. Help please.

CPP / C++ / C Code:
/*
  Write a program which inputs a date in the format dd/mm/yy and outputs it in the
  format month dd, year. For example, 25/12/61 becomes: December 25, 1961
*/

#include <iostream>

using namespace std;

int main()
{
    int day, month, year;
    
    cout << "Enter the date in format dd/mm/yy :" << endl;
    cin >> day >> month >> year;
    
    
    
    switch (month)
    {
           case '1':
                cout << "January" << endl; break;
           case '2':
                cout << "February" << 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 << "Check you date again." << endl; break;
           }
           
           cout << "You entered the following date : \n" << endl;
           cout << month << day << "," << year << endl;
           
           
           return 0;
    
    }
Last edited by admin : 25-Oct-2009 at 04:01. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #2  
Old 25-Oct-2009, 05:16
saqib_ saqib_ is offline
New Member
 
Join Date: Oct 2009
Posts: 12
saqib_ has a little shameless behaviour in the past

Re: The switch statement is not working


This one works. Hard work pays.

CPP / C++ / C Code:
/*
  Write a program which inputs a date in the format dd/mm/yy and outputs it in the
  format month dd, year. For example, 25/12/61 becomes: December 25, 1961
*/

#include <iostream>

using namespace std;

int main()
{
    int day, month, year, usrinput;
    
    cout << "Enter the date in format dd/mm/yy :" << "\n\n"<< endl;
    cin >> day >> month >> year;
       
    switch (month)
    {
           case 1:
                cout << "You have entered: \n\n" << endl;
                cout << "January\t" << day << "," << year << endl;
                break;
           case 2:
                cout << "You have entered: \n\n" << endl;
                cout << "February\t" << day << "," << year << endl;
                break;
           case 3:
                cout << "You have entered: \n\n" << endl;
                cout << "March\t" << day << "," << year << endl;
                break;
           case 4:
                cout << "You have entered: \n\n" << endl;
                cout << "April\t" << day << "," << year << endl;
                break;
           case 5:
                cout << "You have entered: \n\n" << endl;
                cout << "May\t" << day << "," << year << endl;
                break;
           case 6:
                cout << "You have entered: \n\n" << endl;
                cout << "June\t" << day << "," << year << endl;
                break;
           case 7:
                cout << "You have entered: \n\n" << endl;
                cout << "July\t" << day << "," << year << endl;
                break;
           case 8:
                cout << "You have entered: \n\n" << endl;
                cout << "August\t" << day << "," << year << endl;
                break;
           case 9:
                cout << "You have entered: \n\n" << endl;
                cout << "September\t" << day << "," << year << endl;
                break;
           case 10:
                cout << "You have entered: \n\n" << endl;
                cout << "October\t" << day << "," << year << endl;
                break;
           case 11:
                cout << "You have entered: \n\n" << endl;
                cout << "November\t" << day << "," << year << endl;
                break;
           case 12:
                cout << "You have entered: \n\n" << endl;
                cout << "December\t" << day << "," << year << endl;
                break;
           default:
                   cout << "Check you date again." << endl; break;
           }
           
            return 0;
    
}
Last edited by admin : 25-Oct-2009 at 05:32. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with modifying code for vehicle dashboard cluster jdmack36 C Programming Language 1 24-Jul-2007 10:15
Keypad interfacing with TMS320F2812 skn82 C Programming Language 4 09-May-2007 08:41
Switch Statement errors <"jump to case label...crosses initialization of `class..."> jkube1980 C++ Forum 3 28-Mar-2007 15:31
Switch Statement Problem dontcare C++ Forum 3 14-Oct-2004 22:23
Help a C++ Idiot: I am trying to fill an array based on a switch statement. Psycop C Programming Language 2 14-Apr-2004 03:12

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:49.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.