My assignment asked me to do a sport rental system, i meet some proble

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 3393 Views - Last Post: 07 January 2014 - 04:33 AM Rate Topic: -----

#16 kenking125   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-January 14

Re: My assignment asked me to do a sport rental system, i meet some proble

Posted 06 January 2014 - 04:38 AM

View Posttarmizi_adam2005, on 05 January 2014 - 11:35 PM, said:

Hi,

I'm not sure if I follow you correctly, but I think a structure would do. Something like

struct badminton
{
  int court_a =1;
  int court_b =2;
  int court_c=3;
  int court_d=4;
};


then you could do something like check the user input(booked) if its either 1,2,3 or 4. If its one of these four, then keep track of it. Just an idea. Maybe someone here would give a better suggestion though.


thanks for help, but what i want is example like when the court booked by ppl at 8pm-9pm, so other still can book this court at others time but not 8pm-9pm.
the code just able for me track the court, but i dunno how to track it booked by what time/not available at which time.
Was This Post Helpful? 0
  • +
  • -

#17 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7915
  • View blog
  • Posts: 26,425
  • Joined: 05-May 12

Re: My assignment asked me to do a sport rental system, i meet some proble

Posted 06 January 2014 - 08:42 AM

You are still not showing us your design for data structures to keep track of that information. All you have been doing is showing us code for inputting data.
Was This Post Helpful? 0
  • +
  • -

#18 kenking125   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-January 14

Re: My assignment asked me to do a sport rental system, i meet some proble

Posted 06 January 2014 - 08:52 PM

sorry for my stupid question, we must build a data structures? data structures is used for? can provide some website to me study??
Thankyou for gain my knowledge
Was This Post Helpful? 0
  • +
  • -

#19 kenking125   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-January 14

Re: My assignment asked me to do a sport rental system, i meet some proble

Posted 06 January 2014 - 09:19 PM

struct badminton
{
	char court_a[2]="b1";
	char court_b[2]="b2";
	char court_c[2]="b3";
	char court_d[2]="b4";
};



why i get data member initializer is not allowed?

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include <time.h>

struct badminton
{
	char court_a[2]="b1";
	char court_b[2]="b2";
	char court_c[2]="b3";
	char court_d[2]="b4";
};


//GLOBAL VARIABLES
int sport;
int mainmenu;
int ncourt;
char name[100];
char cname[100];
float start;
float end;
float price;
char day[100];
char date[100];
int again;



//DECLARING FUNCTIONS
/*"Genarate Bill"FUNCTION STARTS HERE*/
void gb()
{
printf(" \n\n\n****************Sport Space********************** \n");
printf("Staff : %s\n",name);
printf("Customer Name: %s\n\n",cname);
printf(" ****************Your Booking********************** \n");
printf("\n\nYou selected Badminton Court\n");
printf("Number of court you booking: %d\n",ncourt);
printf("           Court Start Time:%.2f\n",start);
printf("             Court End Time:%.2f\n",end);
printf("        Day Of Court Booked:%s\n",day);
printf("   Date Of The Court Booked:%s\n",date);
printf( "\n               Total price:RM %.2f\n\n",price);
printf("\n\nDo you want to another order (1-Yes, 2-No):\n\n\n");
scanf("%d",&again);
switch(again)
{
case 1:
	{
	main();
	break;
	}
case 2:
	{
		printf("Thank you");
	}
}
}

void gb2()
{
printf(" \n\n\n****************Sport Space********************** \n");
printf("Staff : %s\n",name);
printf("Customer Name: %s\n\n",cname);
printf(" ****************Your Booking********************** \n");
printf("\n\nYou selected Tennis\n");
printf("Number of court you booking: %d\n",ncourt);
printf("           Court Start Time:%.2f\n",start);
printf("             Court End Time:%.2f\n",end);
printf("        Day Of Court Booked:%s\n",day);
printf("   Date Of The Court Booked:%s\n",date);
printf( "\n               Total price:RM %.2f\n\n",price);
printf("\n\nDo you want to another order (1-Yes, 2-No):\n\n\n");
scanf("%d",&again);
switch(again)
{
case 1:
	{
	main();
	break;
	}
case 2:
	{
		printf("Thank you");
		exit;
	}
}
}

void gb3()
{
printf(" \n\n\n****************Sport Space********************** \n");
printf("Staff : %s\n",name);
printf("Customer Name: %s\n\n",cname);
printf(" ****************Your Booking********************** \n");
printf("\n\nYou selected Squash Court\n");
printf("Number of court you booking: %d\n",ncourt);
printf("           Court Start Time:%.2f\n",start);
printf("             Court End Time:%.2f\n",end);
printf("        Day Of Court Booked:%s\n",day);
printf("   Date Of The Court Booked:%s\n",date);
printf( "\n               Total price:RM %.2f\n\n",price);
printf("\n\nDo you want to another order (1-Yes, 2-No):\n\n\n");
scanf("%d",&again);
switch(again)
{
case 1:
	{
	main();
	break;
	}
case 2:
	{
		printf("Thank you");
		exit;
	}
}
}

void gb4()
	{
printf(" \n\n\n****************Sport Space********************** \n");
printf("Staff : %s\n",name);
printf("Customer Name: %s\n\n",cname);
printf(" ****************Your Booking********************** \n");
printf("\n\nYou selected Futsal Court\n");
printf("Number of court you booking: %d\n",ncourt);
printf("           Court Start Time:%.2f\n",start);
printf("             Court End Time:%.2f\n",end);
printf("        Day Of Court Booked:%s\n",day);
printf("   Date Of The Court Booked:%s\n",date);
printf( "\n               Total price:RM %.2f\n\n",price);
printf("\n\nDo you want to another order (1-Yes, 2-No):\n\n\n");
scanf("%d",&again);
switch(again)
{
case 1:
	{
	main();
	break;
	}
case 2:
	{
		printf("Thank you");
	}
}
}

/*"Booking" FUNCTION STARTS HERE*/
void booking () 
{
    printf(" Sport Activities :  Opening/Closing Time     Price(Per Hour):   Court Label\n"); 
	printf("----------------------------------------------------------------------------\n");
	printf("1)Badminton          07:00AM-10:00PM          RM16.00        \t   1-A  \n");
	printf("                                                             \t   2-B  \n");
	printf("                                                             \t   3-C  \n");
	printf("                                                             \t   4-D  \n");
	printf("----------------------------------------------------------------------------\n");
	printf("2)Squash             10:00AM-10:00PM          RM10.00        \t   1-A  \n");
	printf("                                                             \t   2-B  \n");
	printf("----------------------------------------------------------------------------\n");
	printf("3)Tennis             08:00AM-07:00PM          RM30.00        \t   1-A  \n");
	printf("                                                             \t   2-B  \n");
	printf("                                                             \t   3-C  \n");
	printf("----------------------------------------------------------------------------\n");
	printf("4)Futsal             07:00AM-10:00PM          RM40.00        \t   1-A  \n");
	printf("                                                             \t   2-B  \n");
	printf("                                                             \t   3-C  \n");
	printf("----------------------------------------------------------------------------\n");

printf("PLEASE SELECT SPORT ACTIVITIES :\n");
scanf("%d", &sport);

switch(sport)
{
case 1:
{
printf("\n\nYou selected Badminton\n");
printf("How many court do you want to book ? \n\n Number Of Court:");
      scanf("%d", &ncourt);
 printf("\nEnter Start Time \n\n Time:"); 
      scanf("%f", &start); 
 printf("\nEnter End Time \n\n Time:"); 
      scanf("%f", &end); 
 printf("\nDay Of Court Booked\n\n Day:");
     scanf("%s",&day);
     if (strcmp(day,"monday")==0)
	 {
        printf("\nSport Space Is Not Available For Booking On Monday,Reenter Day\n\n Day:");
		scanf("%s",&day);
		printf("\nEnter The Date(day/month/year)\n\n Date:");
        scanf("%s",&date);
		if(start>4)
	   {
		price= ((16*(ncourt*(end - start)))+(16*(ncourt*(end - start))*20/100));
		gb();
	   }  
		else
	   {
		price= ((16*(ncourt*(end - start))));
		gb();
	   }  
	 }
	 else
	 {
     printf("\nEnter The Date(day/month/year)\n\n Date:");
     scanf("%s",&date);
	 if(start>4)
	   {
		price= ((16*(ncourt*(end - start)))+(16*(ncourt*(end - start))*20/100));
		gb();
	   }  
		else
	   {
		price= ((16*(ncourt*(end - start))));
		gb();
	   }  
	 break;
	 }
}
case 2:
{
printf("\n\nYou selected Squash\n");
printf("How many court do you want to book ? \n\n Number Of Court:");
      scanf("%d", &ncourt);
 printf("\nEnter Start Time \n\n Time:"); 
      scanf("%f", &start); 
 printf("\nEnter End Time \n\n Time:"); 
      scanf("%f", &end); 
 printf("\nDay Of Court Booked\n\n Day:");
     scanf("%s",&day);
     if (strcmp(day,"monday")==0)
	 {
        printf("\nSport Space Is Not Available For Booking On Monday,Reenter Day\n\n Day:");
		scanf("%s",&day);
		printf("\nEnter The Date(day/month/year)\n\n Date:");
        scanf("%s",&date);
		if(start>4)
	   {
		price= ((10*(ncourt*(end - start)))+(10*(ncourt*(end - start))*20/100));
		gb();
	   }  
		else
	   {
		price= ((10*(ncourt*(end - start))));
		gb();
	   }  
	 }
	 else
	 {
     printf("\nEnter The Date(day/month/year)\n\n Date:");
     scanf("%s",&date);
	 if(start>4)
	   {
		price= ((10*(ncourt*(end - start)))+(10*(ncourt*(end - start))*20/100));
		gb();
	   }  
		else
	   {
		price= ((10*(ncourt*(end - start))));
		gb();
	   }  
	 break;
	 }
}
case 3:
{
printf("\n\nYou selected Tennis\n");
printf("How many court do you want to book ? \n\n Number Of Court:");
      scanf("%d", &ncourt);
 printf("\nEnter Start Time \n\n Time:"); 
      scanf("%f", &start); 
 printf("\nEnter End Time \n\n Time:"); 
      scanf("%f", &end); 
 printf("\nDay Of Court Booked\n\n Day:");
     scanf("%s",&day);
    if (strcmp(day,"monday")==0)
	 {
        printf("\nSport Space Is Not Available For Booking On Monday,Reenter Day\n\n Day:");
		scanf("%s",&day);
		printf("\nEnter The Date(day/month/year)\n\n Date:");
        scanf("%s",&date);
		if(start>4)
	   {
		price= ((30*(ncourt*(end - start)))+(30*(ncourt*(end - start))*20/100));
		gb();
	   }  
		else
	   {
		price= ((30*(ncourt*(end - start))));
		gb();
	   }  
	 }
	 else
	 {
     printf("\nEnter The Date(day/month/year)\n\n Date:");
     scanf("%s",&date);
	 if(start>4)
	   {
		price= ((30*(ncourt*(end - start)))+(30*(ncourt*(end - start))*20/100));
		gb();
	   }  
		else
	   {
		price= ((30*(ncourt*(end - start))));
		gb();
	   }  
	 break;
	 }
}
case 4:
{
printf("\n\nYou selected Futsal\n");
printf("How many court do you want to book ? \n\n Number Of Court:");
      scanf("%d", &ncourt);
 printf("\nEnter Start Time \n\n Time:"); 
      scanf("%f", &start); 
 printf("\nEnter End Time \n\n Time:"); 
      scanf("%f", &end); 
 printf("\nDay Of Court Booked\n\n Day:");
     scanf("%s",&day);
     if (strcmp(day,"monday")==0)
	 {
        printf("\nSport Space Is Not Available For Booking On Monday,Reenter Day\n\n Day:");
		scanf("%s",&day);
		printf("\nEnter The Date(day/month/year)\n\n Date:");
        scanf("%s",&date);
		if(start>4)
	   {
		price= ((40*(ncourt*(end - start)))+(40*(ncourt*(end - start))*20/100));
		gb();
	   }  
		else
	   {
		price= ((40*(ncourt*(end - start))));
		gb();
	   }  
	 }
	 else
	 {
     printf("\nEnter The Date(day/month/year)\n\n Date:");
     scanf("%s",&date);
	 if(start>4)
	   {
		price= ((40*(ncourt*(end - start)))+(40*(ncourt*(end - start))*20/100));
		gb();
	   }  
		else
	   {
		price= ((40*(ncourt*(end - start))));
		gb();
	   }  
	 break;
	 }
}
}
}







//MAIN PROGRAM STARTS HERE
int main()
{
char password1[]="sportspace123";
char password[100];

printf(" ****************WELCOME TO Sport Space Rental SYSTEM********************** \n");
       printf(" Please Enter Your Name\n");
	   scanf("%s",&name);
       printf("Please Enter Your Password\n");
       scanf("%s",&password);
	  if (strcmp (password,password1) ==0)
	  {
printf(" ****************WELCOME TO Sport Space Rental SYSTEM********************** \n");
printf("   MAIN MENU\n   ---------\n");
printf("Please Enter Customer Name\n");
	   scanf("%s",&cname);
printf("\nWHAT DO YOU WANT TO DO :\n 1.Check court availability\n 2.Booking\n\n 3. Exit\n\n\n Choice is : ");
scanf("%d",&mainmenu);

switch(mainmenu)
{
case 1:
{

break;
}
case 2:
{
booking();
break;
}

case 3:
{
break;
}
default:
{
printf("\n INVALID CHOICE!!!\n PRESS ANY KEY TO CONTINUE");
}
}
	  }
	  else
	  {
		  printf("Password Your Enter Invalid, Please Retry\n\n");
		  main();
	  }
}



here my whole code

This post has been edited by Skydiver: 06 January 2014 - 09:57 PM
Reason for edit:: Fixed code tags.

Was This Post Helpful? 0
  • +
  • -

#20 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7915
  • View blog
  • Posts: 26,425
  • Joined: 05-May 12

Re: My assignment asked me to do a sport rental system, i meet some proble

Posted 06 January 2014 - 09:58 PM

First of all, never call main(). It it a special entry point into the program and not meant to be a way for you to try to create a cheap loop or recursion. If you need to get back to the main menu setup the appropriate looping structure.

View Postkenking125, on 06 January 2014 - 11:19 PM, said:

struct badminton
{
	char court_a[2]="b1";
	char court_b[2]="b2";
	char court_c[2]="b3";
	char court_d[2]="b4";
};



why i get data member initializer is not allowed?

Because the syntax of the language doesn't allow you do that when you are declaring a struct.
Was This Post Helpful? 0
  • +
  • -

#21 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7915
  • View blog
  • Posts: 26,425
  • Joined: 05-May 12

Re: My assignment asked me to do a sport rental system, i meet some proble

Posted 06 January 2014 - 10:04 PM

View Postkenking125, on 06 January 2014 - 10:52 PM, said:

sorry for my stupid question, we must build a data structures? data structures is used for? can provide some website to me study??
Thankyou for gain my knowledge

Here's one: http://www.cplusplus...ial/structures/

But I'm surprised that you would need a tutorial or a reason for why you would need one. You should have covered this topic prior to this assignment being given to you.
Was This Post Helpful? 0
  • +
  • -

#22 kenking125   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-January 14

Re: My assignment asked me to do a sport rental system, i meet some proble

Posted 07 January 2014 - 03:56 AM

thanks for keep teaching me, even me is bad.

struct court
{
	char court_ba[2],court_bb[2],court_bc[2],court_bd[2];
}badminton,squash,tennis,futsal;



if i put like this, izzit right in format?
Was This Post Helpful? 0
  • +
  • -

#23 kenking125   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-January 14

Re: My assignment asked me to do a sport rental system, i meet some proble

Posted 07 January 2014 - 04:08 AM

i have a idea,but i dunno how to start.

open a store for each sport,then store the time that booked for each label of court inside.

so that, when check availability,it will show up all details inside store of each sport. In booking if the time match the detial inside the store will give a "not available"message. SO check availability and not able for customer to book when in booking process is solve.

But one thing is i dunno how to start all of this.~T.T
Was This Post Helpful? 0
  • +
  • -

#24 kenking125   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-January 14

Re: My assignment asked me to do a sport rental system, i meet some proble

Posted 07 January 2014 - 04:33 AM

struct court
{
	int sport;
	char court_ba[2],court_bb[2],court_bc[2],court_bd[2];
	float start;
	float end;
	char day[100];
    char date[100];
	float price;
}badminton,squash,tennis,futsal;


after i reorganize my data structure, any problem from here?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2