| | |
Help me! C++
![]() |
•
•
Join Date: Sep 2007
Posts: 1
Reputation:
Solved Threads: 0
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
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)
#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
Last edited by Ancient Dragon; Sep 15th, 2007 at 6:28 pm. Reason: add code tags
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.
You see the problem here.
Please enclose your next post in code tags.
C++ Syntax (Toggle Plain Text)
if(yr>=1990 && month<=2020)
C++ Syntax (Toggle Plain Text)
#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?
![]() |
Other Threads in the C++ Forum
- Previous Thread: coin toss problem
- Next Thread: windows api help
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ char class classes classified code coding compatible compile console conversion count date delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file filewrite forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper homeworksolutions iamthwee icon if...else ifstream input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node object output play pointer problem program programming project python random read recursion reference rpg string strings struct symbol temperature template test text text-file toolkit tree url values variable vector video win32 windows winsock wordfrequency wxwidgets






