c++ - Rental car mileage overage calculation function -
I'm writing to try to create a mileage overage calculation function for a C ++ program I'm going to switch this function There is a problem in working properly within the statement. What I am trying to achieve (or calculate) amount of profit on the limit of carSize mileage * On rent day
Double Calmiles (intimate, day, four carousges) (dual) So far my code is: MilesFee = 0; Double Compact Overage Charge = .05; Double midSizeOverageCharge = .07; Double Full Size Overage Charge = .09; Int compact delimilarity = 20; Int midSizeDailyMilesLimit = 25; Int fullSizeDailyMilesLimit = 30; Switch (carcases) {case 'C': case 'C': {while (mi and GT; compact delimited limit * days) {milesFee = (miles * day) / compact daily Mile limit; } If (milesoff> compact delimited limit) {milesFee = milesFee * Compact overage charge; Cout & lt; & Lt; "Overlays fees" and lieutenant; & Lt; Milfie & lt; & Lt; Endl; break; }} Case 'M': Case 'M': {While (Miles> Midishee Daily Mile Lilit * Day) {milesFee = (Mile * Day) / Midas Daily Mile Limit; } If (milesoffi> Media's Delimiters limit) {milesFee = milesFee * midSizeOverageCharge; Cout & lt; & Lt; "Overlays fees" and lieutenant; & Lt; Milfie & lt; & Lt; Endl; break; }} Case 'F': case 'F': {while (miles> gt; full size daily mile lilit * day) {milesFee = (mile * day) / full size daily mill limit; } If (milesoffy> Full size delimits limit) {milesFee = milesFee * Full size overage charge; Cout & lt; & Lt; "Overlays fees" and lieutenant; & Lt; Milfie & lt; & Lt; Endl; break; }}} Return goods FAI;
}
Your problems include:
- You never break with the two-switch case labels, if-except the conditions.
- Your time limit never ends. There is nothing in parts of that time that ever change conditionally.
He said, this problem is quite simple that you are excluding it:
#include & lt; Iostream & gt; # Include & lt; Semith & gt; Double calmilesfi (int mill, int day, four carcasses) {cost double compact overage charge = .05; Const Double Midisivative Charge = .07; Const. Double full size overage charge = .09; Const int compact delimiteslimit = 20; Const int midSizeDailyMilesLimit = 25; Const int fullSizeDailyMilesLimit = 30; Double Overlage Charge = 0.0; Int dailyMilesLimit = 0; Double Mile = 0; Switches (carousges) {case 'C': Case 'C': Daily mileage = Compact Delimited Limit; Overage charge = Compact overage charge; break; Case 'M': Case 'M': Daily mileage = Medium size daily mail limit; OverageCharge = midSizeOverageCharge; break; Case 'F': Case 'F': DailyMaillimit = Full Size Daily Mile Limit; Overhaase Charge = Full Size Overage Charge; break; } MilesFee = std :: max (0, mi - (day * daily monthly limit)) * Charging more quantity; Std :: cout & lt; & Lt; "Overlays fees" and lieutenant; & Lt; Milfie & lt; & Lt; Std :: endl; Return miles; }
As I mentioned in the comment, I recommend not using floating point for currency calculation unless it is mandatory for your assignment. You can do the final result as a floating point value, but was I writing that I use the integer precision to some hard range (such as 10th of pani) and floating point conversion once , and the last .
Comments
Post a Comment