Ok so, I have this task and it seems simple enough, and I may be over looking something or over thinking it, but I would like some outside feed back. The problem is this: I'm creating a parking cost calculator and the cost cannot be more than $5 if the Arrival time is after 5pm or the departure time is before 8am. this is what I have so far:
// test_computeCost.cpp
//
// computeCost and a test driver
#include <iostream>
using namespace std;
struct Time
{
int h, m;
};
void computeCost( const Time & in, const Time & out,
float & cost )
{
if ( (in.h*60 + in.m) > (out.h*60 + out.m) )
cout << "Arrival can't be later than departure time"<<endl;
//if ((in.h*60 + in.m) < (out.h*60 + out.m)) //I'm not sure if I should comment out or not
in.h=1; in.m=5;
out.h=8; out.m=0;
//the above values are just test values that make the time statement true
cout << cost <<endl;
return 0;
}
-----------
ok so here's another question is there a way for something like cost <= 5; to actually work to make cost never exceed 5 while the time conditions are met? or do I have something in the wrong order?? please help!! thanks!
You can't assign a range to a variable. The ONLY assignment operator in C/++ is =.
What you need is to first check that cost>5, and if it is, set it to 5.
Unfortunately I've done that in attempts in a way to fix it but it didn't result in the correct outcomes... I think I may just have to go with that if I can't find another solution though. thanks for confirming the range thing though :)