0

THe program works - its is the last piece of code I am having trouble with. I am supposed the wirte and function (month_conversion) which changes the int month that is represented in the input by (montnNumber and monthNumber1 input that number which represents the month and conver that number into months - I tried to write the function with a static_cast<char> and a static_cast<string> and that did not work - I tried callint the function months to the month_conversion function but it started to input number again - I just want to take monthNumber and MonthNumber1 and convert their numbers to month.The reason I only out a small piece of the months in ths function is because if I can get one month to conver correctly then I will input the rest of the months - do anyone have an idea how I can convert the int months to the actual months -Thankst

int month_conversion(int monthly, int monthly1) {

   int November;
   int number;

      switch (toupper(ch1)) {
         case 'J':  // figure out Jan, June, or July
          number = 1; //Jan for now
          break;
         case 'A':  // April or Aug?
          number = 4; // guess April
          break;

         case 'p':  // April or Aug?
          number = 8; // guess April
          break;

          case 'F': case 'f':
          number = 2; // February
          break;

          case 'O': case 'o':
          number = 10; // October
          break;

          case 'S':case 's':           
          number = 9;  
          break;

          case 'N': case 'n':          
          number = November;
          break;
          case 'D':case 'd':             
          number = 12; 
         cout << endl;
         break;



      }

         return number;

()

******************************************************************* 
 Author: Brenda Ross
 Class:  CS 361

 Assignment:

 Program Description: A renewal and cancellation notices to magazine subscribers

 Input: Subscription year, Subscriber, Current month 

 Output: Renewal status,Client, Start date,Account Status

 Calculations: Subcription
*******************************************************************************/

#include<iostream>
#include<string>
#include<iomanip>

using namespace std;

const int END_YEAR = 2014;
const int START_YEAR = 2009;  
/*******************************************************************************

 Funtion month - displays the months in numbers - if ivalid letter is
 entered continues loop until valid letter is entered

*******************************************************************************/
int months ();

/*******************************************************************************

 Funtion yearReading - Takes 2009 and 2014 and error checks the year of subscription
  if te year is Below 2009 or above 2014 will issue the erro  _ invalda month.
*******************************************************************************/
int yearReading (int& date);

/*******************************************************************************

 Funtion  - subcriber_month - Takes 2009 and 2014 and error checks the year of subscription
  if te year is Below 2009 or above 2014 will issue the erro  _ invalda month.
*******************************************************************************/
int subcriber_month (int& buy_month);

/*******************************************************************************

 Funtion  - yearReading - five year span from 2004 to 2009 -if improper dates 
 are enter program should output - invalid year. 
*******************************************************************************/
double yearReading ( double& start_date);

int month_conversion(int monthly, int monthly1);


int main()
{ 


  int convert_month;
  int subscribe_info;
  int order_date;

  int monthNumber;
  int currentYear;
  int begin_date;

  int monthNumber1;//reuse function months
  int expire_month;

  double expire_year; 
  double buyYear;  
  double buy_year;

  string firstName;
  string lastName;

 cout << endl;
 cout <<" Enter subscriber first name ";
 getline (cin, firstName);
 cout <<" Enter subscriber last name  ";
 getline (cin, lastName);   
      monthNumber = months(); 
      currentYear = yearReading(begin_date);

      subscribe_info = subcriber_month ( order_date);  
      monthNumber1 = months();
      buy_year = yearReading (buyYear);
      convert_month = month_conversion( monthNumber,monthNumber1);

  cout << fixed << showpoint << setprecision(2) << endl;
  cout << endl << endl << endl;
  cout <<" Current Date "<<monthNumber<<" "<< currentYear<<endl;
  cout <<" " << lastName<<" "<< firstName << endl << endl; 
  cout <<" Start Subscription: " << monthNumber1 << " " ; 
  cout << static_cast<int>(buyYear) <<endl;

       if(monthNumber1 == 1) {
          expire_month = monthNumber1 + 11;          
       } else 
          expire_month = monthNumber1 - 1;

      expire_year = buyYear + subscribe_info;

  cout <<" Expiration Date " <<expire_month<<" " <<static_cast<int> (expire_year);





  cout << endl;

 cout<<endl<<endl;
  cout << "Press [enter] to exit" <<endl;
  cin.ignore(); //needed because of keyboard input
  cin.get();
  return 0;
}



 char ch,ch1,ch2,ch3;

 int months ( ){ 
   bool valid;
   char ch, ch2, ch3, ch4;
   int number;
   cout << endl;
   do {
      cout << endl; 
      valid = true;  
      cout <<" Enter first letter of the subscription month ";
      cin >> ch1;


      switch (toupper(ch1))  {

       case 'F': case 'f':
       number = 2; 
       break;

       case 'O': case 'o':
       number = 10; 
       break;

       case 'S':case 's':           
       number = 9;  
       break;

       case 'N': case 'n':          
       number = 11;
       break;

       case 'D': case 'd':
       number = 12; 
       break;    

       break;  

       case 'A':
       case 'a':
        cout << " Enter a second letter: ";
        cin >> ch1;


      switch (toupper(ch1)){  

       case 'P' :case 'p':
       number = 04;        
       break;

       case 'U': case 'u':
       number = 8;  
       break;
      }  
       break;           //Break switch for April and August

       case 'J': case 'j': // January, June, or July

       cout << " Enter a second letter: ";
       cin >> ch1;


      switch (toupper(ch1))   {  //Second switch for January, June and July

       case 'A': case 'a':
       number = 1; 
       break;

       case 'U':
       case 'u':
       cout << " Enter a third letter: ";
       cin >> ch2;


      switch (toupper(ch2)) {   //switch inside switch for June and July

       case 'N': case 'n':
       number = 06;
       break;

       case 'L': case 'l':
       number = 07; 
       break;         

      }
       break;    //break from inside switch                      

      }
       break;     //break from inner switch

       case 'M':              
       case 'm':
       cout << " Enter a second letter ";
       cin >> ch2; 


       cout <<" Enter a third letter ";
       cin >> ch3;  


      switch (toupper(ch3)) {            

       case 'R': case 'r':
       number = 03;
       break;

       case 'Y': case 'y':
       number = 05;  
       break;

      }           
       break;

       default:  

       valid = false;  
      }
        if (valid)
         {return number;}
        else
         {cout << " Invalid number";}            
      } while (true);

    }

int yearReading ( int& date)  {


   cout <<" Enter subscription start year ";
   cin >> date;
   cout <<endl;


       if ((START_YEAR > date)||( END_YEAR < date ))
           {cout <<" Invalid year"<<endl;}    
         else 
           return date;         
 }
 int subcriber_month (int& buy_month) {
    int purchase_month; 

     cout <<" Enter the number of years subcribed " ;
     cin >> purchase_month;
     return purchase_month;    

   }



double yearReading ( double& start_date)  {

   const int BUY_YEAR = 2004;
   cout <<" Enter subscription start year ";
   cin >> start_date;


       if (( start_date  < BUY_YEAR)||( START_YEAR < start_date ))
           {cout <<" Invalid year" <<endl;}    
         else 
           return start_date;        
 }

int month_conversion(int monthly, int monthly1) {



   int November;
   int number;



      switch (toupper(ch1)) {
         case 'J':  // figure out Jan, June, or July
          number = 1; //Jan for now
          break;
         case 'A':  // April or Aug?
          number = 4; // guess April
          break;

         case 'p':  // April or Aug?
          number = 8; // guess April
          break;

          case 'F': case 'f':
          number = 2; // February
          break;

          case 'O': case 'o':
          number = 10; // October
          break;

          case 'S':case 's':           
          number = 9;  
          break;

          case 'N': case 'n':          
          number = November;
          break;
          case 'D':case 'd':             
          number = 12; 
         cout << endl;
         break;



      }

         return number;

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by sfuo
0

I don't know why you are putting two numbers into your month function to return one number.

Are you trying to take the number month and convert it into a word?
For example:
1 = January
2 = Febuary
3 = March...

If so try this.

string monthConverter(int num)
{
	string monthout;
	switch(num)
	{
		case 1:
			monthout = "January";
			break;
		case 2:
			monthout = "Febuary";
			break;
		case 3:
			monthout = "March";
			break;
		case 4:
			monthout = "April";
			break;
		case 5:
			monthout = "May";
			break;
		case 6:
			monthout = "June";
			break;
		case 7:
			monthout = "July";
			break;
		case 8:
			monthout = "August";
			break;
		case 9:
			monthout = "September";
			break;
		case 10:
			monthout = "October";
			break;
		case 11:
			monthout = "November";
			break;
		case 12:
			monthout = "December";
			break;
		default:
			monthout = "Invalid";
			break;
	}
	return monthout;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.