943,719 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 791
  • C++ RSS
Sep 15th, 2007
0

Help me! C++

Expand Post »
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
C++ Syntax (Toggle Plain Text)
  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 6:28 pm. Reason: add code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
leolima is offline Offline
1 posts
since Sep 2007
Sep 15th, 2007
0

Re: Help me! C++

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.

C++ Syntax (Toggle Plain Text)
  1. if(yr>=1990 && month<=2020)
You see the problem here.
Reputation Points: 47
Solved Threads: 17
Posting Whiz in Training
Tight_Coder_Ex is offline Offline
215 posts
since Feb 2005
Sep 15th, 2007
0

Re: Help me! C++

C++ Syntax (Toggle Plain Text)
  1.  
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int mDays;
  9. int maxhours;
  10. char pkg = 'Z';
  11. cout << "Enter pkg A, B or C: ";
  12. cin >> pkg;
  13. if ( pkg == 'A' || pkg == 'a' || pkg == 'b'
  14. || pkg == 'B' || pkg == 'C' || pkg == 'c' )
  15. {
  16. int month;
  17. cout << "Enter Month 1 through 12: ";
  18. cin >> month;
  19. if ( month >= 1 && month <= 12 )
  20. {
  21. int hrs;
  22. cout << "Enter hrs: ";
  23. cin >> hrs;
  24. if ( month == 1 || month == 3 || month == 5
  25. || 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. else if ( month == 2 )
  36. {
  37. mDays = 28;
  38. maxhours = 672;
  39. }
  40. else
  41. {
  42. mDays = 29;
  43. maxhours = 696;
  44. }
  45. int yr;
  46. cout << "Enter Year 1990 - 2020" << endl;
  47. cin >> yr;
  48. if ( yr >= 1990 && month <= 2020 )
  49. {
  50. if ( ( yr % 4 ) != 0 ) //leap year
  51. {
  52. }
  53. }
  54. else
  55. {
  56. cout << " Year " << yr << " invalid " << endl;
  57. }
  58. }
  59. else
  60. {
  61. cout << "Month " << month << " invalid" << endl;
  62. }
  63. }
  64. else
  65. {
  66. cout << "Inalid pkg value" << endl;
  67. }
  68. }

Your if else statements look rather odd at first glance? Maybe?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: coin toss problem
Next Thread in C++ Forum Timeline: windows api help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC