Calendar did not run correctly

This is a discussion on Calendar did not run correctly within the C++ Programming forums, part of the General Programming Boards category; The calendar does not show all 12 month, the output only show the name of the month and the input ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    10

    Calendar did not run correctly

    The calendar does not show all 12 month, the output only show the name of the month and the input of the year... how to solve it???
    or i need to create a loop in switch????

    Code:
    #include <iostream>
    #include <string>
    
    
    using namespace std;
    
    int main()
    {
    	int year, day_code, leap_year;
    	int y1, y2, y3;
    	int hari_dalam_bulan, hari, bulan;
    	bool amik = false;
    	
    	cout << " Enter year for the calendar : " ;
    	
    	cin >> year;
    
    	y1 = (year - 1)/4;
    	y2 = (year - 1)/100;
    	y3 = (year - 1)/400;
    	
    	day_code = (year + y1 + y2 + y3) %7;
    
    	if( year%4==0 && year%100!=0 || year%400==0 )
    	
    	
    		amik = true;
    	
    	
    	else
    	
    		amik = false;
    	
    	
    	cout << "                   " ;
    
    	for ( bulan = 1; bulan <=12; bulan++ )
    	{
    		switch(bulan)
    			{
    				
    				case 1 : cout << "\n\nJanuary                     " << year;
    						 hari_dalam_bulan = 31;
    						 break;
    						 
    		        case 2 : cout << "\n\nFebruary                    " << year;
    		        	     hari_dalam_bulan = leap_year ? 29:28;
    		        		 break;
    		        		 
           		    case 3 : cout << "\n\nMarch                       " << year;
           		    		 hari_dalam_bulan = 31;
           		    		 break;
           		    		 
        		    case 4 : cout << "\n\nApril                       " << year;
        		    		 hari_dalam_bulan = 30;
        		    		 break;
        		    		 
       		        case 5 : cout << "\n\nMay                         " << year;
       		        		 hari_dalam_bulan = 31;
       		        		 break;
       		        		 
           		    case 6 : cout << "\n\nJune                        " << year;
           		    		 hari_dalam_bulan = 30;
           		    		 break;
           		    		 
        		    case 7 : cout << "\n\nJuly                        " << year;
        		    		 hari_dalam_bulan = 31;
        		    		 break;
        		    		 
        		    case 8 : cout << "\n\nAugust                      " << year;
        		    		 hari_dalam_bulan = 31;
        		    		 break;
        		    		 
        		    case 9 : cout << "\n\nSeptember                   " << year;
        		             hari_dalam_bulan = 30;
        		             break;
        		             
                    case 10: cout << "\n\nOctober                     " << year;
                    		 hari_dalam_bulan = 31;
                    		 break;
                    		 
           		    case 11: cout << "\n\nNovember                    " << year;
           		    		 hari_dalam_bulan = 30;
           		    		 break;
           		    		 
        		    case 12: cout << "\n\nDecember                    " << year;
        		    		 hari_dalam_bulan = 31;
        		    		 break;
        		    		 
        		 }
    	 }
     	 day_code = ( day_code + hari_dalam_bulan ) % 7;
    	 
    	 cout << "\n\nSun  Mon  Teu  Thu Fri Sat Sun\n" ;
    	 
    	 for ( hari=1 ; hari<= 1 + day_code * 5; hari++ )
    	 cout << " ";
    	 
    	 for ( hari=1 ; hari<= hari_dalam_bulan; hari++ )
    	 	{
            	cout <<  hari;
            	
            	if ((hari + day_code) % 7 > 0)
            		cout << "   ";
            		
           		else
           			cout << "\n ";
    	 	}
    	 	
    
    	 	cout << year << day_code;
    	 	
    	 	
    	 	system ("pause");
    	 	return 0;
    	 
     
    	
    	
    }

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Format your code better and you would see that you're braces are lined up incorrectly. You want the for loop
    Code:
    for ( bulan = 1; bulan <=12; bulan++ )
    to encompass the whole program up until
    Code:
    cout << year << day_code;
    Also, I'd like to mention that your output is just as poorly formatted as your code. Your week also doesn't contain wednesday.
    Last edited by SlyMaelstrom; 04-15-2006 at 06:38 AM.
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. calculating the mode
    By bigggame in forum C Programming
    Replies: 10
    Last Post: 06-13-2006, 03:04 AM
  2. How I can Run exe file in C++
    By palang in forum C++ Programming
    Replies: 2
    Last Post: 05-10-2006, 11:55 AM
  3. MSVC: run w/o debugger vs run w/ debuger
    By skorman00 in forum C++ Programming
    Replies: 2
    Last Post: 01-24-2006, 08:49 PM
  4. How to run an another app from C++?
    By Hankyaku in forum C++ Programming
    Replies: 8
    Last Post: 04-30-2003, 12:08 PM
  5. Replies: 2
    Last Post: 10-29-2002, 03:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21