Help me! C++

Reply

Join Date: Sep 2007
Posts: 1
Reputation: leolima is an unknown quantity at this point 
Solved Threads: 0
leolima leolima is offline Offline
Newbie Poster

Help me! C++

 
0
  #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 6:28 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 195
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++

 
0
  #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.

  1. if(yr>=1990 && month<=2020)
You see the problem here.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
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 iamthwee is a splendid one to behold 
Solved Threads: 376
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Help me! C++

 
0
  #3
Sep 15th, 2007
  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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC