//THIS PROJECT IS LISTED ON MY GITHUB PROFILE
//We are using _CRT_SECURE_NO_WARNINGS in order to be able to use (scanf)
#define _CRT_SECURE_NO_WARNINGS
SetConsoleOutputCP(CP_UTF8);
#include <stdio.h> //<--- External headers
#include <stdlib.h> //<--- External headers
#include <string.h> //<--- External headers
#include <conio.h> //<--- External headers
/*Colours will be used to enhnance the user experience
and provide guidance. For example Green (Success); Red
(Error); Yellow (Information) .. https://www.theurbanpenguin.com/4184-2/ */
#include "colours.h" // <--- This is my own header, located as a seperate file.
//This is the header, where I store all my global variables that I need access
anywhere
//In the program.
#include "global_variables.h" //<--- This is my own header, located as a seperate
file.
void files() {
//NAMING THE FILES POINTERS
FILE* sales_data; FILE* payment_details;
//OPENING THE FILES
//WE HAVE TO OPEN THE FILES WAY BEFORE THE PROGRAM BEGINS, TO ENSURE THAT
//WHEN THE SALES PAGE IS OPEN, THE PROGRAM DOES NOT CRASH
//THE PROGRAM WILL LOOK FOR THOSE FILES AND IF THEY DO NOT EXIST, IT WILL
THROW AN ERROR.
//Source: https://www.guru99.com/c-file-input-output.html
//"append mode. If a file is in append mode, then the file is opened. The
content within the file doesn’t change."
sales_data = fopen("sales_data.txt", "a"); payment_details =
fopen("payment_details.txt", "a");
fclose(sales_data); fclose(payment_details);
}
//Pauses the program function
void pause_program() {
char pause;
scanf("\n%hd\n", &pause);
}
//Clear program screen function
void clearScreen() {
system("cls");
}
//Allows user to return to the main menu
void back_to_menu() {
printf("Enter (y) to return to the menu -- (n) to exit the program.\n");
char backinput;
//Filter user Input
//This is used at the end of every purchase, to allow the user to return to the
menu.
fscanf(stdin, "\n%c", &backinput);
, if (backinput == 'y') {
//If their input is equal to y, execute the function below
//Take user back to the main menu.
main();
clearScreen();
}
//If their input is equal to n, execute the code below:
else if (backinput == 'n') {
exit(1);
}
//If their input is not matching n or y, then execute the code below:
else {
printf("Sorry, invalid option");
}
}
//Main main, present user with 3 options to choose from.
int show_menu() {
reset();
clearScreen();
printf(":----------------------------------:\n");
yellow();
printf(": M A I N M E N U :\n");
reset();
printf(":----------------------------------:\n");
printf(":----------------------------------:\n");
printf(": Please select an option :\n");
printf(": 1. Buy Cars :\n");
printf(": 2. View sales Data :\n");
printf(": 3. View Cars Stock :\n");
printf(": 4. Admin :\n");
printf(":----------------------------------:\n");
printf(": Welcome to MOD003212 Car Sales :\n");
green();
printf(": Software author: Kaloyan Titov :\n");
reset();
printf(": Local time @%s :\n", __TIME__);
cyan();
printf(": https://github.com/kaloyannt :\n");
reset();
printf(":----------------------------------:\n");
//\n (new line) in order to ignore my previous input of y or n and allow me
to enter a new input.
printf("Option /> "); scanf("\n%c", &menu_option);
}
//Show cars Available
//This function, will be used to reset and set the stock,
//Every time when the program is closed and re-opened.
int carsAvailable() {
//Naming the file
FILE* carsAvailable;
//Creating the file, before the program executes.
carsAvailable = fopen("carsAvailable.txt", "w");
//Writing the amount of cars declared to the file.
fprintf(carsAvailable, "%d", setCarStock); // <-- This variable contains the
, amount of stock to write to the file.
// The setCarStock variable is stored in global_variables.h file.
//Closing the file
fclose(carsAvailable);
//Opening the file again, but to read this time.
carsAvailable = fopen("carsAvailable.txt", "r");
//Creating a new int variable named scanCarsAvailable, to scan the contents
of the file and put them
//Into the variable named cars
unsigned long cars;
int scanCarsAvailable = fscanf(carsAvailable, "%d", &cars);
//If variable cars (which contains the number from the file) is more than 0
//Run the code below:
if (cars > 0) {
printf("%d", cars);
}
//If is less than 0, then display that there is no more stock;
else {
printf("No more cars available");
}
//Close the file again
fclose(carsAvailable);
}
//This would update the GLOBAL stock, once any purchase has been made.
int updatedGlobalStock() {
//Updating the global car stock, when a car model is purchased.
//This is a arithmetic calculation that will updated the stock
//Accordingly, depending on how many cars have been brought for each brand.
//The stock will be updated globally in the program.
setCarStock -= carsNeededMercedes;
setCarStock -= carsNeededAudi;
setCarStock -= carsNeededToyota;
setCarStock -= carsNeededPorsche;
setCarStock -= carsNeededBmw;
}
/*This is the purchase screen that the user is presented with, once
They have selected the model number "101" */
int purchaseScreenMercedes() {
//NAMING THE FILES POINTERS
FILE* sales_data; FILE* payment_details;
//OPENING THE FILES
//WE HAVE TO OPEN THE FILES WAY BEFORE THE PROGRAM BEGINS, TO ENSURE THAT
//WHEN THE SALES PAGE IS OPEN, THE PROGRAM DOES NOT CRASH
//THE PROGRAM WILL LOOK FOR THOSE FILES AND IF THEY DO NOT EXIST, IT WILL
THROW AN ERROR.
//Source: https://www.guru99.com/c-file-input-output.html
//"append mode. If a file is in append mode, then the file is opened. The
content within the file doesn’t change."
sales_data = fopen("sales_data.txt", "a"); payment_details =
fopen("payment_details.txt", "a");