| | |
Help me! C++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
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 beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






