View Single Post
Old 12-02-2004, 04:06 PM   #1 (permalink)
zero2
Junkie
 
zero2's Avatar
 
[C] Help Im getting some strange answers

Im a beginner at C, and I need some help.

The problem that I have is a problem that calculates parking fee based on several variables.

For instance if it is a car then the first 3 hrs is free, if after 3 hrs 1.50. There's also two more vehicles such as a truck & bus that have unique rates.

Also if the vehicle is parked beyond midnight the vehicle is towed. Time is based on military time ex. 1:00 p.m. is 13:00.

The way that the book wants the info entered is with 5 scanf statements:

Type of vechicle?

Hour vehicle entered lot (0 - 24)?

Minute vehicle entered lot (0 - 59)?

Hour vehicle left lot (0 - 24)?

Minute vehicle left lot (0 - 59)?


So basically I have 4 integers named hrEnter, minEnter, hrOut, minOut. To evaluate the time as a whole I convert them to a float, using a modulo, and add them to the hr variable ex.(12hr + .20min = 12.20). Because I did it this way I get this weird error saying : error C2296: '%' : illegal, left operand has type 'float'. Plus, I get a bunch of these warning C4244: '=' : conversion from 'double' to 'float', possible loss of data.

Besides that, I just found another problem it mentions something about rounding the min. of to the next hour before creating the charge, I've never learned how to do that? This situation seems to get worse everytime I look at it.

I pretty much kind of have the logic worked out, but I'm not sure on a couple of things, such as rounding numbers.

Here's some of the code that I started:

Code:
 
/* This is Problem 58, Chapter 5 in the C book
Writen By: zero2
*/
#include <stdio.h>
int main (void)
{
/* Local Definitions */
char vehicle;
float bill;
int hrEnter;
int minEnter;
int hrOut;
int minOut;
float minFin;
int hrFin;
float time;


/* Statements */
printf("Type of vechicle?\n");
scanf("%c", &vehicle);
printf("Hour vehicle entered lot (0 - 24)?\n");
scanf("%d", &hrEnter);
printf("Minute vehicle entered lot (0 - 59)?\n");
scanf("%d", &minEnter);
printf("Hour vehicle left lot (0 - 24)?\n");
scanf("%d", &hrOut);
printf("Minute vehicle left lot (0 - 59)?\n");
scanf("%d", &minOut);

if (minEnter > minOut)
{
	minFin = minOut + 60;
	minFin = (minFin - minEnter) %100 ;
	hrFin = hrOut - 1;
	hrFin = hrFin - hrEnter;
	printf("%d : %2.2f\n", hrFin, minFin);
}
else
{	
hrFin = hrOut - hrEnter;
	minFin = (minOut - minEnter) %100;
	printf("%d : %f\n", hrFin, minFin);
}
if (hrFin < 0)
{
	printf("Vehicle later than midnight-Tow\n");
}
if (vehicle = 'c')
	if (hrFin <= 3)
	{
		bill =  0.00;
		printf("bill for car: %2.2f\n", bill);
	}
	else
	{
		time = hrFin + minFin;
		printf("time is %.2f", time);
		bill = (time - 3.00) * 1.50;
printf("bill for car: %.2f\n", bill);
	}
if (vehicle = 't')
{
	if (hrFin <= 2)
	
		time = hrFin + minFin;
		bill = time * 1.00;
		printf("bill for truck: %.2f\n", bill);
	}
	else
	{
		time = hrFin + minFin;
		bill = ((time - 2.00) * 2.30) + 2.00;
		printf("bill for truck: %.2f\n", bill);
	}
    return 0;
}
/* main */
/* Results: */
TIA, I appreciate any help or suggestions.
zero2 is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360