RSS Forums RSS

Help me! C++

Please support our C++ advertiser: Programming Forums
Reply
Posts: 1
Reputation: leolima is an unknown quantity at this point 
Solved Threads: 0
leolima leolima is offline Offline
Newbie Poster

Help me! C++

  #1  
Sep 15th, 2007
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
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. void main()
  6. {
  7. int mDays;
  8. int maxhours;
  9.  
  10. char pkg = 'Z';
  11. cout<<"Enter pkg A, B or C: ";
  12. cin >> pkg;
  13.  
  14. if( pkg == 'A'||pkg =='a' ||pkg =='b' ||pkg == 'B'|| pkg == 'C'||pkg =='c' )
  15. {
  16. int month;
  17. cout<<"Enter Month 1 through 12: ";
  18. cin>>month;
  19.  
  20. if(month>=1 && month<=12)
  21. {
  22. int hrs;
  23. cout<<"Enter hrs: ";
  24. cin>>hrs;
  25. if (month==1||month==3||month==5||month==7||month==8||month==10||month==12)
  26. {
  27. mDays = 31;
  28. maxhours = 744;
  29. }
  30. else if(month== 4 || month==6 || month==9 || month==11)
  31. {
  32. mDays = 30;
  33. maxhours = 720;
  34.  
  35. }
  36. else if(month ==2)
  37. {
  38. mDays = 28;
  39. maxhours = 672;
  40. }
  41. else
  42. {
  43. mDays = 29;
  44. maxhours = 696;
  45. }
  46.  
  47. int yr;
  48. cout<<"Enter Year 1990 - 2020"<<endl;
  49. cin>>yr;
  50.  
  51. if(yr>=1990 && month<=2020)
  52. {
  53. if((yr%4)!=0) //leap year
  54. {
  55.  
  56. }
  57.  
  58.  
  59.  
  60. }
  61. else
  62. {
  63. cout<<" Year " << yr << " invalid "<<endl;
  64. }
  65.  
  66.  
  67.  
  68. }
  69.  
  70. else
  71. {
  72. cout<<"Month " << month << " invalid"<<endl;
  73. }
  74.  
  75.  
  76.  
  77. }
  78.  
  79. else
  80. {
  81. cout<<"Inalid pkg value"<<endl;
  82. }
  83. }//end main
Last edited by Ancient Dragon : Sep 15th, 2007 at 5:28 pm. Reason: add code tags
AddThis Social Bookmark Button
Reply With Quote  
Posts: 184
Reputation: Tight_Coder_Ex is an unknown quantity at this point 
Solved Threads: 13
Tight_Coder_Ex's Avatar
Tight_Coder_Ex Tight_Coder_Ex is offline Offline
Junior Poster

Re: Help me! C++

  #2  
Sep 15th, 2007
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.
Reply With Quote  
Posts: 5,068
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 355
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Help me! C++

  #3  
Sep 15th, 2007
 
#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?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the C++ Forum
Views: 674 | Replies: 2 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:06 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC