HELP! C-Programming assignment (uni) (1 Viewer)

r.haidar

not crusin til schoolies!
Joined
Oct 19, 2004
Messages
196
Location
a
Gender
Male
HSC
2005
i cant get this piece of shit to work...
any1 got any ideas? its an assignment due tomorow (13th april) lol *im so organised*

the bulk of this assignment is there, so dont try n write me a new code, thats plagarism champs... lol just lemme know how i can get it to work :'( much appreciated!

(see attachment)
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
1) validateVehicleType is passed C, c, B, b, T and t, whose values have never been initialised.

2) Why pass validateVehicleType as arguments when C, c, B, b, T and t are already module wide variables?

3) validateVehicleType's if block is using = not ==

4) Theres true and theres false, don't #define a true2 to make things confusing. Return 0, 1 or 2, or some other more meaningful #defined values.

Getting those fixed might be a start.
 

r.haidar

not crusin til schoolies!
Joined
Oct 19, 2004
Messages
196
Location
a
Gender
Male
HSC
2005
dude im a n00b... ur gunna have to explain to me in people terms lol

1... no idea what u mean

2.. as above lol

3... assuming i should make it = and not ==, i get an Ivalue error or something

4... i need true2 to make a 50%discount for a parking time over 12 hours
 
Last edited:

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
1. You are comparing Type to B, b, C, c, T and t, but those variables (B, b, C, c, T and t) have never been given any values. Imagine being told in math to do:
Type = 1
Is Type = x true?
You can't answer this since x doesn't have a value.

2. Never mind.

3. Fix 1 first.

4. #defining True, False, and True2 is like giving the choices of Yes, No and YesNo to a question. You can #define something more meaningful like NO_DISCOUNT, OVER_12_HOURS etc.
 

r.haidar

not crusin til schoolies!
Joined
Oct 19, 2004
Messages
196
Location
a
Gender
Male
HSC
2005
sunny said:
1. You are comparing Type to B, b, C, c, T and t, but those variables (B, b, C, c, T and t) have never been given any values. Imagine being told in math to do:
Type = 1
Is Type = x true?
You can't answer this since x doesn't have a value.
yeah but they arent numbers, theyre inputs from someone telling the program the type of vehicle they own... what initial value am i meant to give? C = car?
 

Mumma

Member
Joined
May 19, 2004
Messages
586
Location
Sydney
Gender
Male
HSC
2006
well, if they input C, then cant you just make C a string = 'C'?
I didnt even read the assignment sheet so this is a random suggestion.

Code:
if( validateVehicleType( C, c, B, b, T, t ) == 1 )
		printf("Correct Vehicle Type\n");
			else 
				printf("Wrong Vehicle Type - Restart Program\n");
I dont do C, only Python, but what the hell is going on here? Shouldnt you be passing the users input to the function :confused:
Why are you passing C,c,B,b,T and t? Arnt they global?
 
Last edited:

r.haidar

not crusin til schoolies!
Joined
Oct 19, 2004
Messages
196
Location
a
Gender
Male
HSC
2005
Mumma said:
well, if they input C, then cant you just make C a string = 'C'?
I didnt even read the assignment sheet so this is a random suggestion.

Code:
if( validateVehicleType( C, c, B, b, T, t ) == 1 )
		printf("Correct Vehicle Type\n");
			else 
				printf("Wrong Vehicle Type - Restart Program\n");
I dont do C, only Python, but what the hell is going on here? Shouldnt you be passing the users input to the function :confused:
Why are you passing C,c,B,b,T and t? Arnt they global?
yeah thats at the start... thats calling on the function (validate etc) and if it returns a value of 1, print that the vehicle type is correct... i dont really know what passing means so im gunna nod and smile lol im screwed for this assignment :'(
 

Jaydels

Member
Joined
Oct 31, 2004
Messages
472
Location
somewhere you're not
Gender
Female
HSC
2005
r.haidar said:
i cant get this piece of shit to work...
any1 got any ideas? its an assignment due tomorow (13th april) lol *im so organised*

the bulk of this assignment is there, so dont try n write me a new code, thats plagarism champs... lol just lemme know how i can get it to work :'( much appreciated!

(see attachment)
this is how i did mine...

int validateVehicleType(char vehicleType)
{
switch(vehicleType)
{
case 'c':
case 'C':
return TRUE;
break;

case 'b':
case 'B':
return TRUE;
break;

case 't':
case 'T':
return TRUE;
break;

default:
return FALSE;
};
then in the main function....

if(validateVehicleType(vehicleType) == 0) {
printf("Wrong vehicle type!");
return 1;
} else {
printf("Enter parking time (hours): ");
}
 

r.haidar

not crusin til schoolies!
Joined
Oct 19, 2004
Messages
196
Location
a
Gender
Male
HSC
2005
ok this is what ive got as my 'final' program... but the last line of output is fucked up...

Code:
#include <stdio.h>	 	 	 	 	 	 	 	    
#define CAR_RATE 	                3
#define BUS_RATE 	                5
#define TRUCK_RATE 	6
#define TRUE		1
#define FALSE		0
#define DISCOUNT 	                0.5

/* defining variables */
float Time, fee;
float C, c, B, b, T, t;
char Type;

/* function declarations */
int validateVehicleType(char vehicleType);
float validateParkingTime( float Time );
float calculateParkingFee( float car, float bus, float truck, int fee);
float displayParkingFee( int fee );

int main(void)
{	 
		printf("Enter your vehicle type- Car = C, Bus = B, Truck = T :");
		scanf("%c", &Type);
	
		if(validateVehicleType(Type) == 0) 
		{
			printf("Wrong vehicle type!");
			return 1;
		} 
		else 
			{
				printf("Enter parking time (hours): ");
				scanf("%f", &Time);
			}
		
	if( validateParkingTime( Time ) == 1)
		printf("Correct Time Entered\n");
		else if( validateParkingTime( Time ) == DISCOUNT)
			fee = fee * 0.5;
				else
				printf("Incorrect Time Value - Restart Program\n");
					
	displayParkingFee( fee );	   	   
}

/* function definitions */
int validateVehicleType(char Type)
	{
	switch(Type)
		{
			case 'c':
			case 'C':
			return TRUE;
				break;
	
			case 'b':
			case 'B':
			return TRUE;
				break;
	
			case 't':
			case 'T':
			return TRUE;
				break;
	
			default:
			return FALSE;
		}
	}
	
float validateParkingTime( float Time )
	{
		if(Time < 1)
			return(FALSE);
		if((Time < 12) && (Time > 0))
			return(TRUE);
		if((Time > 12));
			return(DISCOUNT);
	}
	
float calculateParkingFee( float car, float bus, float truck, int fee)
	{
		if((Type = C) || ( Type = c))
			fee = CAR_RATE * Time;
		if((Type = B) || ( Type = b))
			fee = BUS_RATE * Time;
		if((Type = T) || ( Type = t))
			fee = TRUCK_RATE * Time;
		else 
			printf("Invalid Value\n");
	}

float displayParkingFee( int fee )
	{
		printf("%c parking fee is %d. \n", Type, fee);
	}
why wont u just work :'(
 
Last edited:

Jaydels

Member
Joined
Oct 31, 2004
Messages
472
Location
somewhere you're not
Gender
Female
HSC
2005
if( validateParkingTime( Time ) == 1)
printf("Correct Time Entered\n");
else if( validateParkingTime( Time ) == DISCOUNT)
fee = fee * 0.5;
else
printf("Incorrect Time Value - Restart Program\n");
the last 'else' should be in line with the if i think
also, the discount is only given after 12 hours....ie if you park for 13 hrs you pay full price for the first 12 hrs and then the last hour is discounted
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top