Hey guys!

CAn u tell me if my program is right?

First, I need to get a Pkg and validate;
Second,get month and validate;
Third, determinate max hours;
*If FEB;
Fourth, get year and validate(1990-2020)
check for leap yr.
Fifth, get hours and validate against maxhours;
and calculate the bill ^^(month)

I have 3 pkg
PKG A = $12 month
PKG B = $18 " " "
PKG C = $25 " " "

Thank you!!

Thx

#include <iostream>
using namespace std;


void main()
{
	int mDays;
	int maxhours;

    char pkg = 'Z';
		cout<<"Enter pkg A, B or C: ";
	    cin >> pkg;
    
    if( pkg == 'A'||pkg =='a' ||pkg =='b' ||pkg == 'B'|| pkg == 'C'||pkg =='c' )
    {
        int month;
        cout<<"Enter Month 1 through 12: ";
        cin>>month;

		if(month>=1 && month<=12)
			{
			int hrs;
			    cout<<"Enter hrs: ";
				cin>>hrs;
				if (month==1||month==3||month==5||month==7||month==8||month==10||month==12)
				{
						mDays = 31;
						maxhours = 744;
				}
				else if(month== 4 || month==6 || month==9 || month==11)
				{
						mDays = 30;
						maxhours = 720;
						
				}				
				else if(month ==2)
				{
						mDays = 28;
						maxhours = 672;
				}
				else
				{
					   mDays = 29;
					   maxhours = 696;
				}
					
				   int yr;
				   cout<<"Enter Year 1990 - 2020"<<endl;
				  cin>>yr;

					if(yr>=1990 && month<=2020)
					{
						if((yr%4)!=0) //leap year
						{
							
						}



				                }
					else
					{
				     cout<<" Year " << yr << " invalid "<<endl; 
					}
				
					
				
			}

		else
			{
			cout<<"Month " << month << " invalid"<<endl; 
			}


		
	}
	
	else
	{
		cout<<"Inalid pkg value"<<endl;
	}
}//end main

It almost looks like you threw something out in the wind in the hopes that someone will fix it up for you. Clean up your code with indentation to begin with so it's a little more legible. Then run it to see if you get the results you expect. Right off hand without spending to much time it appears the only time leaps years will be evaluated is when the month is less than 1 or greater than 12.

Please enclose your next post in code tags.

if(yr>=1990 && month<=2020)

You see the problem here.

Member Avatar for iamthwee
#include <iostream>
 
using namespace std; 
 
int main()
{
  int mDays;
  int maxhours;
  char pkg = 'Z';
  cout << "Enter pkg A, B or C: ";
  cin >> pkg;
  if ( pkg == 'A' || pkg == 'a' || pkg == 'b' 
      || pkg == 'B' || pkg == 'C' || pkg == 'c' )
  {
    int month;
    cout << "Enter Month 1 through 12: ";
    cin >> month;
    if ( month >= 1 && month <= 12 )
    {
      int hrs;
      cout << "Enter hrs: ";
      cin >> hrs;
      if ( month == 1 || month == 3 || month == 5 
          || month == 7 || month == 8 || month == 10 || month == 12 )
      {
        mDays = 31;
        maxhours = 744;
      }
      else if ( month == 4 || month == 6 || month == 9 || month == 11 )
      {
        mDays = 30;
        maxhours = 720;
      }
      else if ( month == 2 )
      {
        mDays = 28;
        maxhours = 672;
      }
      else
      {
        mDays = 29;
        maxhours = 696;
      }
      int yr;
      cout << "Enter Year 1990 - 2020" << endl;
      cin >> yr;
      if ( yr >= 1990 && month <= 2020 )
      {
        if ( ( yr % 4 ) != 0 ) //leap year
        {
        } 
      }
      else
      {
        cout << " Year " << yr << " invalid " << endl;
      } 
    }
    else
    {
      cout << "Month " << month << " invalid" << endl;
    } 
  }
  else
  {
    cout << "Inalid pkg value" << endl;
  }
}

Your if else statements look rather odd at first glance? Maybe?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.