Hi, I'm having problems with an assignment, could someone help me?
Task: Create software that simulates tracking the movement of a moving stretcher or elevator. We know that we have this type of software, and by creating it, you will go through a series of elements that we covered during the winter semester. Initially, through the project, you will test your personal programming logic, then the method of setting up and creating the project, as well as the method of collecting, printing and presenting data to end users.
For the purposes of the project, we initially have to create two sides, the user side and the admin side, after that we need to create options through which we can set the commands that we will list in the rest of the text, which will represent the structure and our basic functionality.
The basic functionality of the program would be that the admin can specify the size of the object and the number of stretcher movements before servicing, we also need to have an option to monitor the current number of movements as well as print out the elevators that are in the queue for servicing. While the user side has access to activate the stretcher, and during the activation we need to graphically simulate the movement of an object through the terminal, this of course depends on the data created by the admin, which refers to the number of floors and the number of movements.I have an error and I can't print the user part.
#include <stdio.h>
#include <string.h>
#define MAX_USERS 10
#define MAX_NAME_LENGTH 30
#define MAX_EMAIL_LENGTH 50
#define MAX_PASSWORD_LENGTH 20
struct Admin {
char email[MAX_EMAIL_LENGTH];
char password[MAX_PASSWORD_LENGTH];
} admin;
int main() {
// Učitavanje admin podataka iz fajla "admin.dat"
FILE *fp = fopen("admin.dat", "r");
if(fp==NULL){
printf("Ne postoji fajl admin.dat, molimo vas da ga napravite\n");
return 0;
}
fread(&admin, sizeof(admin), 1, fp);
fclose(fp);
char email[MAX_EMAIL_LENGTH], password[MAX_PASSWORD_LENGTH];
printf("Unesite email: ");
scanf("%s", email);
printf("Unesite lozinku: ");
scanf("%s", password);
// Provjera da li su uneseni podaci ispravni
if (strcmp(email, "(e-mail address removed)") == 0 && strcmp(password, "admin") == 0) {
printf("Ulogovani ste kao admin.\n");
int choice;
do {
printf("Admin opcije:\n");
printf("1. Kreiranje novog korisnika\n");
printf("2. Kreiranje novog nosila\n");
printf("3. Trenutni broj koristenja nosila\n");
printf("4. Nosila spremna za servisiranje\n");
printf("5. Blokirana nosila\n");
printf("6. Exit\n");
printf("Izbor: ");
scanf("%d", &choice);
switch (choice) {
case 1:
// Kreiranje novog korisnika
char newEmail[MAX_EMAIL_LENGTH], newPassword[MAX_PASSWORD_LENGTH];
printf("Unesite novi email: ");
scanf("%s", newEmail);
printf("Unesite novu lozinku: ");
scanf("%s", newPassword);
// Snimanje novog korisnika u fajl "admin.dat"
fp = fopen("admin.dat", "w");
if(fp==NULL){
printf("Ne postoji fajl admin.dat, molimo vas da ga napravite\n");
return 0;
}
strcpy(admin.email, newEmail);
strcpy(admin.password, newPassword);
fwrite(&admin, sizeof(admin), 1, fp);
fclose(fp);
printf("Korisnik uspjesno kreiran.\n");
break;
case 2:
// Kreiranje novog nosila
struct Nosilo {
char ime[256];
int sprat;
int korisnik;
int servis;
} nosilo;
printf("Unesite naziv nosila: ");
scanf("%s", nosilo.ime);
printf("Unesite broj spratova gdje se nosilo koristi: ");
scanf("%d", &nosilo.sprat);
printf("Unesite koliko puta se nosilo moze aktivirati prije servisa: ");
scanf("%d", &nosilo.korisnik);
printf("Unesite broj koji se dodaje na broj koristenja kada se oznaci za servis: ");
scanf("%d", &nosilo.servis);
// Snimanje novog nosila u fajl "nosila.dat"
fp = fopen("nosila.dat", "a");
if(fp==NULL){
printf("Ne postoji fajl nosila.dat, molimo vas da ga napravite\n");
return 0;
}
fwrite(&nosilo, sizeof(nosilo), 1, fp);
fclose(fp);
printf("Nosilo uspjesno kreirano.\n");
break;
case 3:
// Trenutni broj korištenja nosila
char naziv_nosila[256];
printf("Unesite naziv nosila: ");
scanf("%s", naziv_nosila);
struct koristenje_nosilo {
char ime[256];
int trenutno_koristenja;
int sprat;
int korisnik;
int servis;
} koristenje_nosilo;
// Citanje nosila iz fajla "nosila.dat"
fp = fopen("nosila.dat", "r");
if(fp==NULL){
printf("Ne postoji fajl nosila.dat, molimo vas da ga napravite\n");
return 0;
}
while(fread(&nosilo, sizeof(nosilo), 1, fp)){
if(strcmp(nosilo.ime, naziv_nosila) == 0){
printf("Naziv nosila: %s\n", nosilo.ime);
printf("Trenutno koristenja: %d\n", koristenje_nosilo.trenutno_koristenja);
printf("Razlika izmedu trenutnog stanja i servisiranja/blokiranja: %d\n", koristenje_nosilo.korisnik - koristenje_nosilo.trenutno_koristenja + koristenje_nosilo.servis);
break;
}
}
fclose(fp);
break;
case 4:
//Nosila spremna za servis
int servisiranje[20];
// Inicijaliziraj niz na 0
for (int i = 0; i < 20; i++)
servisiranje = 0;
// Prikaz nosila koja su ispunila zadati broj
for (int i = 0; i < 20; i++) {
if (servisiranje == 1)
printf("Naziv nosila: %d\n", i);
}
// Funkcija za resetiranje nosila i
// postavljanje niza na 0
void resetNosila()
{
for (int i = 0; i < 20; i++)
servisiranje = 0;
}
case 5:
// Blokirana nosila
printf("Blokirana nosila\n");
int blokiranje[20];
// Inicijaliziraj niz na 0
for (int i = 0; i < 20; i++)
blokiranje = 0;
// Prikaz nosila koja su ispunila zadati broj
for (int i = 0; i < 20; i++) {
if (blokiranje == 1)
printf("Naziv nosila: %d\n", i);
}
case 6:
printf("Izlaz iz programa\n");
break;
default:
printf("Pogresan izbor\n");
break;
}
} while (choice != 6);
} else {
printf("Unijeli ste pogresne podatke.\n");
}
}
Task: Create software that simulates tracking the movement of a moving stretcher or elevator. We know that we have this type of software, and by creating it, you will go through a series of elements that we covered during the winter semester. Initially, through the project, you will test your personal programming logic, then the method of setting up and creating the project, as well as the method of collecting, printing and presenting data to end users.
For the purposes of the project, we initially have to create two sides, the user side and the admin side, after that we need to create options through which we can set the commands that we will list in the rest of the text, which will represent the structure and our basic functionality.
The basic functionality of the program would be that the admin can specify the size of the object and the number of stretcher movements before servicing, we also need to have an option to monitor the current number of movements as well as print out the elevators that are in the queue for servicing. While the user side has access to activate the stretcher, and during the activation we need to graphically simulate the movement of an object through the terminal, this of course depends on the data created by the admin, which refers to the number of floors and the number of movements.I have an error and I can't print the user part.
#include <stdio.h>
#include <string.h>
#define MAX_USERS 10
#define MAX_NAME_LENGTH 30
#define MAX_EMAIL_LENGTH 50
#define MAX_PASSWORD_LENGTH 20
struct Admin {
char email[MAX_EMAIL_LENGTH];
char password[MAX_PASSWORD_LENGTH];
} admin;
int main() {
// Učitavanje admin podataka iz fajla "admin.dat"
FILE *fp = fopen("admin.dat", "r");
if(fp==NULL){
printf("Ne postoji fajl admin.dat, molimo vas da ga napravite\n");
return 0;
}
fread(&admin, sizeof(admin), 1, fp);
fclose(fp);
char email[MAX_EMAIL_LENGTH], password[MAX_PASSWORD_LENGTH];
printf("Unesite email: ");
scanf("%s", email);
printf("Unesite lozinku: ");
scanf("%s", password);
// Provjera da li su uneseni podaci ispravni
if (strcmp(email, "(e-mail address removed)") == 0 && strcmp(password, "admin") == 0) {
printf("Ulogovani ste kao admin.\n");
int choice;
do {
printf("Admin opcije:\n");
printf("1. Kreiranje novog korisnika\n");
printf("2. Kreiranje novog nosila\n");
printf("3. Trenutni broj koristenja nosila\n");
printf("4. Nosila spremna za servisiranje\n");
printf("5. Blokirana nosila\n");
printf("6. Exit\n");
printf("Izbor: ");
scanf("%d", &choice);
switch (choice) {
case 1:
// Kreiranje novog korisnika
char newEmail[MAX_EMAIL_LENGTH], newPassword[MAX_PASSWORD_LENGTH];
printf("Unesite novi email: ");
scanf("%s", newEmail);
printf("Unesite novu lozinku: ");
scanf("%s", newPassword);
// Snimanje novog korisnika u fajl "admin.dat"
fp = fopen("admin.dat", "w");
if(fp==NULL){
printf("Ne postoji fajl admin.dat, molimo vas da ga napravite\n");
return 0;
}
strcpy(admin.email, newEmail);
strcpy(admin.password, newPassword);
fwrite(&admin, sizeof(admin), 1, fp);
fclose(fp);
printf("Korisnik uspjesno kreiran.\n");
break;
case 2:
// Kreiranje novog nosila
struct Nosilo {
char ime[256];
int sprat;
int korisnik;
int servis;
} nosilo;
printf("Unesite naziv nosila: ");
scanf("%s", nosilo.ime);
printf("Unesite broj spratova gdje se nosilo koristi: ");
scanf("%d", &nosilo.sprat);
printf("Unesite koliko puta se nosilo moze aktivirati prije servisa: ");
scanf("%d", &nosilo.korisnik);
printf("Unesite broj koji se dodaje na broj koristenja kada se oznaci za servis: ");
scanf("%d", &nosilo.servis);
// Snimanje novog nosila u fajl "nosila.dat"
fp = fopen("nosila.dat", "a");
if(fp==NULL){
printf("Ne postoji fajl nosila.dat, molimo vas da ga napravite\n");
return 0;
}
fwrite(&nosilo, sizeof(nosilo), 1, fp);
fclose(fp);
printf("Nosilo uspjesno kreirano.\n");
break;
case 3:
// Trenutni broj korištenja nosila
char naziv_nosila[256];
printf("Unesite naziv nosila: ");
scanf("%s", naziv_nosila);
struct koristenje_nosilo {
char ime[256];
int trenutno_koristenja;
int sprat;
int korisnik;
int servis;
} koristenje_nosilo;
// Citanje nosila iz fajla "nosila.dat"
fp = fopen("nosila.dat", "r");
if(fp==NULL){
printf("Ne postoji fajl nosila.dat, molimo vas da ga napravite\n");
return 0;
}
while(fread(&nosilo, sizeof(nosilo), 1, fp)){
if(strcmp(nosilo.ime, naziv_nosila) == 0){
printf("Naziv nosila: %s\n", nosilo.ime);
printf("Trenutno koristenja: %d\n", koristenje_nosilo.trenutno_koristenja);
printf("Razlika izmedu trenutnog stanja i servisiranja/blokiranja: %d\n", koristenje_nosilo.korisnik - koristenje_nosilo.trenutno_koristenja + koristenje_nosilo.servis);
break;
}
}
fclose(fp);
break;
case 4:
//Nosila spremna za servis
int servisiranje[20];
// Inicijaliziraj niz na 0
for (int i = 0; i < 20; i++)
servisiranje = 0;
// Prikaz nosila koja su ispunila zadati broj
for (int i = 0; i < 20; i++) {
if (servisiranje == 1)
printf("Naziv nosila: %d\n", i);
}
// Funkcija za resetiranje nosila i
// postavljanje niza na 0
void resetNosila()
{
for (int i = 0; i < 20; i++)
servisiranje = 0;
}
case 5:
// Blokirana nosila
printf("Blokirana nosila\n");
int blokiranje[20];
// Inicijaliziraj niz na 0
for (int i = 0; i < 20; i++)
blokiranje = 0;
// Prikaz nosila koja su ispunila zadati broj
for (int i = 0; i < 20; i++) {
if (blokiranje == 1)
printf("Naziv nosila: %d\n", i);
}
case 6:
printf("Izlaz iz programa\n");
break;
default:
printf("Pogresan izbor\n");
break;
}
} while (choice != 6);
} else {
printf("Unijeli ste pogresne podatke.\n");
}
}