Step 1 is learn how to indent code consistently.
If the code is clearly laid out, it's a lot easier for others to read, and easier for you to spot problems.
Code:
#include <stdio.h>
//#include <conio.h>
void Rent(void);
float entry(int);
float discount(int, float);
int j = 0;
struct rental {
char firstname[20];
char lastname[20];
int number[10];
char address[40];
int age;
} rents[40];
int main()
{
int num1;
printf("Welcome to Ollivierre's Car Rental Service!\n"
"Do you want to rent a car or are you returning one?\n"
"1.Renting\n"
"2.Returning\n"
"0.Exit\n");
scanf("%d", &num1);
while (num1 != 0) {
switch (num1) {
case 1:
Rent();
break;
}
}
printf("Have a nice day!");
return 0;
}
void Rent()
{
int entrance, num2, num3, num4, car;
float rate, discop;
FILE *rentPtr;
rentPtr = fopen("Rental.txt", "w");
printf("You have chosen to rent a car\n");
printf("Please Enter your First name: \n");
scanf("%s", &rents[j].firstname);
printf("Please Enter your Last name: \n");
scanf("%s", &rents[j].lastname);
printf("Please Enter your Address: \n");
scanf("%s", &rents[j].address);
printf("Please Enter your Telephone Number: \n");
scanf("%d", &rents[j].number);
printf("Please Enter your Age(Must be at least age 20)): \n");
scanf("%d", &rents[j].age);
entrance = rents[j].age;
if (entrance > 20) {
printf("What type of vehicle would you like?\n"
"These are the vehicles available.\n");
printf("1.Toyota Camry($30)\n"
"2.Mitsubishi lancer($60)\n"
"3.Bugatti veyron($95)\n"
"4.Lamborghini gallardo ($90)\n"
"5.Nissan Altima($80)\n"
"6.mitsubishi galant ($45)\n");
printf("Which vehicle would you like to rent?\n");
scanf("%d", num2);
car = entry(num2);
printf("The price of your car per day is %0.2f", car);
printf("How many days will you be renting this car for?: \n");
scanf("%d", num4);
rate = car * num4;
if (num4 > 10) {
discop = discount(num4, rate);
printf("You are renting the car for: %d day(s).\n"
"The price would be: %0.2f\n", num4, discop);
} else {
if (num4 < 10) {
printf("You are renting the car for: %d day(s).\n"
"The price would be %0.2f", num4, rate);
}
}
fprintf(rentPtr, "Firstname\tLastname\tAddress\tNumber\tAge");
fprintf(rentPtr, "\n");
fprintf(rentPtr, "%s\t%s\t%s\t%d\t%d", rents[j].firstname, rents[j].lastname,
rents[j].address, rents[j].number, rents[j].age);
fclose(rentPtr);
} else {
if (entrance <= 19) {
printf("You are too young to rent a car!\n");
}
}
printf("Have a nice day!");
}
float entry(int a)
{
float price;
if (a == 1) {
price = 30;
} else {
if (a == 2) {
price = 60;
} else {
if (a == 3) {
price = 95;
} else {
if (a == 4) {
price = 90;
} else {
if (a == 5) {
price = 80;
} else {
if (a == 6) {
price = 45;
}
}
}
}
}
}
return price;
}
float discount(int b, float c)
{
float disco;
if ((b > 10) && (b < 21)) {
disco = c - (c * .02);
} else {
if ((b > 20) && (b < 41)) {
disco = c - (c * .05);
} else {
if (b > 40) {
disco = c - (c * .10);
}
}
}
return disco;
}
Next, get a compiler that can tell you a lot more about what is wrong with your program before you try to run it.
Code:
$ gcc -Wall -Wextra foo.c
foo.c: In function ‘Rent’:
foo.c:48:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[20]’ [-Wformat=]
scanf("%s", &rents[j].firstname);
^
foo.c:50:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[20]’ [-Wformat=]
scanf("%s", &rents[j].lastname);
^
foo.c:52:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[40]’ [-Wformat=]
scanf("%s", &rents[j].address);
^
foo.c:54:9: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int (*)[10]’ [-Wformat=]
scanf("%d", &rents[j].number);
^
foo.c:69:11: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat=]
scanf("%d", num2);
^
foo.c:71:12: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘int’ [-Wformat=]
printf("The price of your car per day is %0.2f", car);
^
foo.c:73:11: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat=]
scanf("%d", num4);
^
foo.c:87:22: warning: format ‘%d’ expects argument of type ‘int’, but argument 6 has type ‘int *’ [-Wformat=]
fprintf(rentPtr, "%s\t%s\t%s\t%d\t%d", rents[j].firstname, rents[j].lastname,
^
foo.c:41:23: warning: unused variable ‘num3’ [-Wunused-variable]
int entrance, num2, num3, num4, car;
^
foo.c:69:5: warning: ‘num2’ may be used uninitialized in this function [-Wmaybe-uninitialized]
scanf("%d", num2);
^
foo.c:73:5: warning: ‘num4’ may be used uninitialized in this function [-Wmaybe-uninitialized]
scanf("%d", num4);
^
You have a lot of printf / scanf calls where the format string is inconsistent with the parameter available.