diff --git a/README.md b/README.md index 35e63f4..5055a05 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -# Programming-Skills-Level1 +# Programming-Skills-Level-1-week-2 -This repository is the second one of a series of entry-level exercises that can be solved in any programming language. The purpose of these exercises is to develop your programming logic. This repository is the first in a series of more exercises to improve your programming skills. - -Author: @blindma1den +This repository is the second one of a series of entry-level exercises that can be solved in any programming language. In my case i decided to solve them in C language. They are not perfect or are solved in the more efficient way. diff --git a/appointment_app.c b/appointment_app.c new file mode 100644 index 0000000..3656c30 --- /dev/null +++ b/appointment_app.c @@ -0,0 +1,208 @@ +/*The Valencia Hospital is developing an application to manage appointments. Design an algorithm for this application with the following features: + +It must have a login and validate the data; after the third failed attempt, it should be locked. +The user can schedule an appointment for: General Medicine, Emergency Care, Clinical Analysis, Cardiology, Neurology, Nutrition, Physiotherapy, Traumatology, and Internal Medicine. +There are 3 doctors for each specialty. +The user can only book one appointment per specialist. An error message should be displayed if the user tries to choose two appointments with the same doctor or the same specialty. As a developer, you can choose the doctors' names. +The maximum limit for appointments, in general, is 3. +Upon selecting a specialty, it will display if the user prefers a morning or afternoon appointment and show available hours. As a developer, you can choose the hours. +Display available specialists. +The user can choose their preferred specialist. +The basic process is: Login -> Choose specialty -> Choose doctor -> Choose time slot. +*/ + +#include +#include + +typedef struct user{ + char username[20]; + char password[20]; + int appointments; + int specialties[9]; + char *doctors[3]; + int doctor_index; +}user; +//Procedure to initialize a user data type +void user_constructor(user * u,const int index_u,const char * username, const char * password){ + strcpy(u[index_u].username,username); + strcpy(u[index_u].password,password); + u[index_u].appointments = 0; + u[index_u].doctor_index = 0; + for(int i =0; i <9;i++ ){ + u[index_u].specialties[i]=0; + } +} +//Procedure to erase the data inside of a user data type +void user_erase_data(user * u, const int id,const int specialty_opt){ + u[id].specialties[specialty_opt] = 0; + u[id].doctor_index--; + u[id].doctors[u[id].doctor_index] = ' '; +} + +int main(){ + int menu1 = 1; + int menu_option; + int menu2 ; + char username[20]; + char password[20]; + int specialty_option; + int doctor_option; + int time_option; + int hour_option; + int log_in_counter = 0; + user users[256]; + int user_index = 0; + int user_ID; + int log_in_flag; + int doctor_flag; + char *doctors[]={"Bob","Chacin","Sirica"}; + while(menu1==1){ + printf("Appointment Menu\nPlease select an option\n\n1-Create an account\n2-Log in\n3-Exit\n\n"); + scanf("%i",&menu_option); + switch(menu_option){ + //Creating an Account + case 1: + printf("Creating an Account\nPlease enter a new username(No blank spaces):"); + scanf("%s",username); + printf("Now enter a new password(No blank spaces):"); + scanf("%s",password); + user_constructor(users,user_index,username,password); + user_index++; + for(int i = 0; i < 20; i++){ + username[i]=' '; + password[i]=' '; + } + break; + case 2: + menu2 = 1; + if(user_index>=1){ + while( menu2== 1){ + //Verifying the credentials + for(int i = 0; i < 20; i++){ + username[i]=' '; + password[i]=' '; + } + log_in_flag=0; + printf("Enter your credentials\nUsername:"); + scanf("%s",username); + printf("Now enter your password:"); + scanf("%s",password); + for(int i = 0; i < user_index; i ++){ + if(0 == strcmp(username,users[i].username) && 0 == strcmp(password,users[i].password)){ + user_ID = i; + log_in_flag=1; + } + } + if(users[user_ID].appointments<3){ + //Valid credentials + if(log_in_flag==1){ + if(users[user_ID].appointments<3){ + printf("Please select a specialty:\n\n1-General Medicine\n2-Emergency Care\n3-Clinical Analysis\n4-Cardiology\n5-Neurology\n6-Nutrition\n7-Physiotherapy\n8-Traumatology\n9-Internal Medicine\n\n"); + //Selecting a specialty + scanf("%i",&specialty_option); + if(specialty_option <10 && specialty_option >0){ + specialty_option = specialty_option - 1; + //Verifying if is a valid specialty + if(0 == users[user_ID].specialties[specialty_option]){ + //Saving the specialty choice + users[user_ID].specialties[specialty_option] = 1; + //Showing the doctors + printf("Now select a doctor:\n\n"); + for(int i = 0; i < 3; i++){ + printf("%i- %s\n",i+1,doctors[i]); + } + //Selecting a doctor + scanf("%i",&doctor_option); + if(doctor_option<4 && doctor_option >0){ + doctor_option = doctor_option -1; + doctor_flag= 0; + //Verifying if the user have already an Appointemt with the selected doctor + for(int i = 0; i < users[user_ID].doctor_index; i++){ + if(0 == strcmp(users[user_ID].doctors[i],doctors[doctor_option])){ + doctor_flag = 1; + } + } + if( doctor_flag == 0){ + //saving the doctor choice + users[user_ID].doctors[users[user_ID].doctor_index]=doctors[doctor_option]; + users[user_ID].doctor_index++; + printf("At what time would you like?\n1-Morning\n2-Afternoon\n\n"); + //Selecting a time of the day and hour + scanf("%i",&time_option); + switch(time_option){ + //Morning + case 1: + printf("Now select an hour:\n\n1- 8:00 am\n2- 9:00 am\n3- 10:00 am\n\n"); + scanf("%i",&hour_option); + if(hour_option<4 && hour_option>0){ + printf("Congratulations,your appointment is booked\n\n"); + users[user_ID].appointments++; + }else{ + printf("Invalid option"); + user_erase_data(users,user_ID,specialty_option); + } + + menu2=0; + break; + //Afternoon + case 2: + printf("Now select an hour:\n\n1- 4:00 am\n2- 5:00 am\n3- 6:00 am\n\n"); + scanf("%i",&hour_option); + if(hour_option<4 && hour_option>0){ + printf("Congratulations,your appointment is booked\n\n"); + users[user_ID].appointments++; + }else{ + printf("Invalid option"); + user_erase_data(users,user_ID,specialty_option); + } + menu2=0; + break; + default: + printf("Invalid option\n\n"); + menu2 = 0; + user_erase_data(users,user_ID,specialty_option); + break; + } + }else{ + printf("You already have an appointment with doctor %s\n\n",doctors[doctor_option]); + users[user_ID].specialties[specialty_option] = 0; + } + }else{ + printf("Invalid option\n\n"); + menu2=0; + } + }else{ + printf("You already have an appointment in that specialty\n\n"); + } + }else{ + printf("Invalid option\n\n"); + menu2 = 0; + } + }else{ + printf("Too many appointments"); + menu2=0; + } + }else{ + log_in_counter++; + printf("Wrong credential\n\n"); + if(log_in_counter==3){ + printf("Too many attempts"); + menu2=0; + menu1=0; + } + } + }else{ + printf("You have to many appointments\n\n"); + } + } + }else{ + printf("Please create an account\n\n"); + } + break; + default: + menu1=0; + break; + } + } + return 0; +} \ No newline at end of file diff --git a/best_destination.c b/best_destination.c new file mode 100644 index 0000000..ba27ebf --- /dev/null +++ b/best_destination.c @@ -0,0 +1,114 @@ +/* +A travel agency has a special offer for traveling in any season of 2024. Their destinations are: + +Winter: Andorra and Switzerland. In Andorra, there are skiing activities, and in Switzerland, there's a tour of the Swiss Alps. +Summer: Spain and Portugal. In Spain, there are hiking and extreme sports activities. In Portugal, there are activities on the beaches. +Spring: France and Italy. In France, there are extreme sports activities, and in Italy, there's a cultural and historical tour. +Autumn: Belgium and Austria. In Belgium, there are hiking and extreme sports activities, and in Austria, there are cultural and historical activities. +Note: Traveling in winter costs $100, in autumn $200, in spring $300, and in summer $400. + +Design a system that helps users choose their best destination according to their personal preferences and the season they want to travel in. + Important: With the information you have, you should ask the user the right questions and display on screen what their best destination would be. + +Clue: You could consider the user's budget +*/ + +#include +#include +//Each coutry + +typedef struct country{ + char activities[30]; + char season[10]; + char country_name[15]; + int cost; +}country; + + +int main(){ + country countries[8]; + //First season (Winter) + strcpy(countries[0].activities,"Skiing Activities"); + strcpy(countries[1].activities,"Tour of the Swiss Alphs"); + strcpy(countries[0].season,"winter"); + strcpy(countries[1].season,"winter"); + strcpy(countries[0].country_name,"Andorra"); + strcpy(countries[1].country_name,"Switzerland"); + countries[0].cost = 100; + countries[1].cost = 100; + //Second season(Summer) + strcpy(countries[2].activities,"Hiking and Extreme Sports"); + strcpy(countries[3].activities,"Activities on the Beaches"); + strcpy(countries[2].season,"summer"); + strcpy(countries[3].season,"summer"); + strcpy(countries[2].country_name,"Spain"); + strcpy(countries[3].country_name,"Portugal"); + countries[2].cost = 400; + countries[3].cost = 400; + //Third season(Spring) + strcpy(countries[4].activities,"Extreme Sports"); + strcpy(countries[5].activities,"Cultural and Historical tour"); + strcpy(countries[4].season,"spring"); + strcpy(countries[5].season,"spring"); + strcpy(countries[4].country_name,"France"); + strcpy(countries[5].country_name,"Italy"); + countries[4].cost = 300; + countries[5].cost = 300; + //Forth season (Autumn) + strcpy(countries[6].activities,"Extreme Sports"); + strcpy(countries[7].activities,"Cultural and Historical tour"); + strcpy(countries[6].season,"autumn"); + strcpy(countries[7].season,"autumn"); + strcpy(countries[6].country_name,"Belgium"); + strcpy(countries[7].country_name,"Austria"); + countries[6].cost = 200; + countries[7].cost = 200; + + char * activities [] = {"Skiing","Extreme Sports","Hiking","Tour of the Swiss Alphs","Activities on the Beaches","Cultural and Historical tour"}; + int budget; + int activity; + int flag_season; + int final_choice; + char season[10]; + printf("Travel agency Menu\nPlease respond the next set of questions to help you decide a destination\n"); + //Selecting an activity + printf("Which activity do you prefer?\n1-Skiing\n2-Extreme sports\n3-Hiking\n4-Tour of the Swiss Alphs\n5-Activities on the Beaches\n6-Cultural and Historical Tour\n\n"); + scanf("%i",&activity); + //Selecting a season + printf("Write the season you like the most (Winter,Summer,Autumn,Spring):"); + scanf("%s",season); + //Choosing the budget + printf("Now please enter your budget:"); + scanf("%i",&budget); + //Validations + if(budget<100){ + printf("Invalid amount for budget\n\n"); + }else{ + if(activity<1 || activity>6){ + printf("Invalid activity number\n\n"); + }else{ + flag_season = 0; + for(int i = 0; i < 8;i++){ + if(NULL!=strstr(countries[i].activities,activities[activity-1])){ + flag_season = 1; + } + } + if(flag_season == 0){ + printf("Wrong season\n\n"); + }else{ + //Final choice + final_choice = 0; + for(int i = 0; i < 8;i++){ + if(NULL != strstr(countries[i].activities,activities[activity-1])&& 0 == strcmp(countries[i].season,season)&& countries[i].cost <= budget ){ + printf("Your best destinations is %s\n",countries[i].country_name); + final_choice = 1; + } + } + if(final_choice == 0){ + printf("There no destination available with all those things"); + } + } + } + } + return 0; +} \ No newline at end of file diff --git a/booking_app.c b/booking_app.c new file mode 100644 index 0000000..e453001 --- /dev/null +++ b/booking_app.c @@ -0,0 +1,326 @@ +/*The RH Hotels chain has hired you to design the booking algorithm for their mobile application: + +Login; it should be locked after the third failed attempt. +The RH Hotels chain exists in 5 countries: Spain, France, Portugal, Italy, and Germany. +Each country has its own hotels located in: Madrid, Barcelona, Valencia, Munich, Berlin, Rome, Milan, Paris, Marseille, Madeira, Lisbon, and Porto. +All hotels have 24 rooms each: 6 VIP suites, 3 single rooms, 6 double rooms, 6 group rooms, and 3 luxury suites. +The user can make reservations at any time of the year and at any hour, and book as many rooms as desired. +Single rooms are priced at $100 per night, double rooms at $200 per night, group rooms at $350 per night, VIP suites at $450 per night, and luxury suites at $550 per night, applicable at any time of the year. +The algorithm functions as follows: Login, choose country, choose city, choose room type, select the number of nights, collect user data (name, surname, ID/passport), +print the total cost, and if the user agrees, print a confirmation message for the reservation. If not, return to the main menu.*/ + +#include +#include +//Reservation data type +typedef struct reservation{ + char country[10]; + char city [10]; + char suit_type[10]; + char month[10]; + char day[10]; + char hour[10]; + int cost; +}reservation; + +//User data type +typedef struct user{ + char username[20]; + char password[20]; + char name[20]; + char surname[20]; + char id[20]; + int first_time; + int reservation_index; + int total_cost; + struct reservation reservations[256]; +}user; + +//Procedure to intialize a user data type +void user_constructor(user * u, char * user_u, char * user_p, int user_index){ + for(int i = 0; i < 20; i++){ + u[user_index].username[i]=' '; + u[user_index].password[i]=' '; + u[user_index].name[i]=' '; + u[user_index].surname[i]=' '; + u[user_index].id[i]=' '; + } + strcpy(u[user_index].username,user_u); + strcpy(u[user_index].password,user_p); + u[user_index].reservation_index=0; + u[user_index].total_cost = 0; + u[user_index].first_time = 0; + +} +//Procedure to add a reservation to an user's account +void add_reservation(user* u, int user_index,char * country, char * city,char * month, char * day, char * hour , int cost){ + strcpy(u[user_index].reservations[u[user_index].reservation_index].city , city); + strcpy(u[user_index].reservations[u[user_index].reservation_index].country , country); + strcpy(u[user_index].reservations[u[user_index].reservation_index].month , month); + strcpy(u[user_index].reservations[u[user_index].reservation_index].day , day); + strcpy(u[user_index].reservations[u[user_index].reservation_index].hour , hour); + u[user_index].reservations[u[user_index].reservation_index].cost = cost; + u[user_index].reservation_index++; + u[user_index].total_cost = u[user_index].total_cost + u[user_index].reservations[u[user_index].reservation_index].cost; +} + +//Procedure to add the personal data to an user's account +void add_personal_information(user * u, int user_index, char * name, char *surname, char *id){ + strcpy(u[user_index].name , name); + strcpy(u[user_index].surname, surname); + strcpy(u[user_index].id, id); + u[user_index].first_time=1; +} + +int main(){ + int menu1=1; + int menu2; + int menu_option; + int user_counter = 0; + int log_in_flag; + int log_in_fails = 0; + int user_index; + int country_option; + int place_option; + int city_flag; + char month[10]; + char day[10]; + char hour[5]; + int room_option; + int room_amount; + int nights; + int total_price; + int price_option; + int another_reservation; + user users[256]; + char user_u [20]; + char user_p [20]; + char user_name[20]; + char user_surname[20]; + char user_id[20]; + //Available countries + char * countries []= {"Spain" , "Germany","Italy","France","Portugal"}; + char * cities[5][3]; + //spain's cities + cities[0][0]="Barcelona"; + cities[0][1]= "Madrid"; + cities[0][1]="Valencia"; + //Germany's cities + cities[1][0]="Munich"; + cities[1][1]="Berlin"; + //Italy's cities + cities[2][0]="Rome"; + cities[2][1]="Milan"; + //France's Cities + cities[3][0]="Paris"; + cities[3][1]="Marseille"; + //Portugal's cities + cities[4][0]="Madeira"; + cities[4][1]="Lisbon"; + cities[4][2]="Porto"; + // single rooms, double rooms, group rooms , VIP suites,luxury suites + int rooms[]={ 3 ,6 ,6, 6,3}; + //Price for room + int rooms_price[]={100 ,200, 350,450, 550}; + while(menu1==1){ + //Main Menu + printf("RH Hotels Menu\nPlease Select an option\n1-Create an account\n2-Log in\n3-Exit\n\n"); + scanf("%i",&menu_option); + switch(menu_option){ + //Creating an Account + case 1: + printf("Creating an Account\nPlease enter a new Username(no blanck spaces):"); + scanf("%s",user_u); + printf("Now please enter a new password (No blank spaces):"); + scanf("%s",user_p); + user_constructor(users,user_u,user_p,user_counter); + user_counter++; + for(int i = 0 ; i < 20; i++){ + user_u[i]=' '; + user_p[i]=' '; + } + break; + case 2: + //Log in + if(user_counter>=1){ + printf("Log in\nPlease enter your Credentials\n\nUsername:"); + scanf("%s",user_u); + printf("Now the password:"); + scanf("%s",user_p); + log_in_flag = 0; + //Validating the credentials + for(int i = 0; i < user_counter; i++){ + if(0 == strcmp(users[i].username,user_u) && 0 == strcmp(users[i].password,user_p)){ + log_in_flag = 1; + user_index = i; + } + } + for(int i = 0 ; i < 20; i++){ + user_u[i]=' '; + user_p[i]=' '; + } + //Choosing a Country + if(log_in_flag == 1){ + printf("Log In Successful\n\nNow choose the an hotel location:\n1-Spain\n2-Germany\n3-Italy\n4-France\n5-Portugal\n\n"); + scanf("%i",&country_option); + //Validating the country option + if(country_option<=5 && country_option>0){ + printf("Please select a location:"); + city_flag=0; + //Asking the city based on the choosen country and validating the answer + switch(country_option){ + case 1: + printf("The options are:\n1-Barcelona\n2-Madrid\n3-Valencia\n\n"); + scanf("%i",&place_option); + if(place_option>0 && place_option<4){ + city_flag = 1; + }else{ + printf("Invalid option\n\n"); + } + break; + case 2: + printf("The options are:\n1-Munich\n2-Berlin\n\n"); + scanf("%i",&place_option); + if(place_option==1 || place_option==2){ + city_flag = 1; + }else{ + printf("Invalid option\n\n"); + } + break; + case 3: + printf("The options are:\n1-Rome\n2-Milan\n\n"); + scanf("%i",&place_option); + if(place_option==1 || place_option==2){ + city_flag = 1; + }else{ + printf("Invalid option\n\n"); + } + break; + case 4: + printf("The options are:\n1-Paris\n2-Marseille\n\n"); + scanf("%i",&place_option); + if(place_option==1 || place_option==2){ + city_flag = 1; + }else{ + printf("Invalid option\n\n"); + } + break; + case 5: + printf("The option are:\n1-Madeira\n2-Lisbon\n3-Porto\n\n"); + scanf("%i",&place_option); + if(place_option>0 && place_option<4){ + city_flag = 1; + }else{ + printf("Invalid option\n\n"); + } + break; + default: + printf("Invalid option\n\n"); + break; + } + //Getting the date of the reservation + if(city_flag==1){ + printf("\nEnter the month's name:"); + scanf("%s",month); + printf("\nEnter the day's name:"); + scanf("%s",day); + printf("\nEnter the hour:"); + scanf("%s",hour); + menu2=1; + while(menu2==1){ + //The type of room, amount of rooms and nights + printf("Reservation MENU\n\n"); + printf("Now select a room type\n1-Single room\n2-Double room\n3-Group room\n4-VIP suite\n5-Luxury suite\n\n"); + scanf("%i",&room_option); + if(room_option>0 && room_option<6){ + printf("\nNow enter the amount of rooms:"); + scanf("%i",&room_amount); + if(room_amount<=rooms[room_option-1] && room_amount>0){ + printf("\nPlease enter the number of nights:"); + scanf("%i",&nights); + if(nights>0){ + //Calculating the price + total_price = rooms_price[room_option-1] * nights; + rooms[room_option-1] = rooms[room_option-1] - room_amount; + //Getting the user personal info + //Only the first time we ask the user his personal info + if(users[user_index].first_time==0){ + printf("Enter your name:"); + scanf("%s",user_name); + printf("\nEnter your surname:"); + scanf("%s",user_surname); + printf("\nEnter your ID/Passport number:"); + scanf("%s",user_id); + } + //Showing the total price + printf("The total price would be %i, do you agree ?\n1-Yes\n2-No\n\n",total_price); + scanf("%i",&price_option); + switch(price_option){ + case 1: + add_reservation(users,user_index,countries[country_option-1],cities[country_option-1][place_option-1],month,day,hour,total_price); + if(users[user_index].first_time==0){ + add_personal_information(users,user_index,user_name,user_surname, user_id); + } + printf("\nReservation Successful\n\n"); + //Asking if he wants to make another reservation + printf("Do you want to reserve another type or book?\n1-Yes\n2-No\n\n"); + scanf("%i",&another_reservation); + switch(another_reservation){ + case 1: + break; + case 2: + menu2=0; + printf("\n"); + break; + default: + printf("Invalid option"); + menu2=0; + menu1=0; + break; + } + break; + case 2: + menu2=0; + default: + printf("Invalid option"); + menu2=0; + menu1=0; + break; + } + }else{ + printf("Invalid amount\n\n"); + } + }else{ + printf("There are no enough rooms of that type avalaible, try again\n\n"); + } + }else{ + printf("Invalid option\n\n"); + menu2=0; + } + } + }else{ + printf("Invalid option\n\n"); + menu2=0; + } + }else{ + printf("Invalid option"); + menu2=0; + } + }else{ + printf("Wrong Credentials\n"); + log_in_fails++; + if(log_in_fails == 3){ + printf("Too many Attempts"); + menu1=0; + } + } + }else{ + printf("Please create an Account"); + } + break; + default: + menu1=0; + break; + } + } + return 0; +} \ No newline at end of file diff --git a/player_comparation.c b/player_comparation.c new file mode 100644 index 0000000..d272602 --- /dev/null +++ b/player_comparation.c @@ -0,0 +1,237 @@ +/* +1. Manchester United FC has hired you as a developer. Develop a program that helps the coach identify their fastest player, player with the most goals, assists, passing accuracy, and defensive involvements. +The system should also allow comparison between two players. Use the following player profiles: + +Bruno Fernandes: 5 goals, 6 points in speed, 9 points in assists, 10 points in passing accuracy, 3 defensive involvements. Corresponds to jersey number 8. +Rasmus Hojlund: 12 goals, 8 points in speed, 2 points in assists, 6 points in passing accuracy, 2 defensive involvements. Corresponds to jersey number 11. +Harry Maguire: 1 goal, 5 points in speed, 1 point in assists, 7 points in passing accuracy, 9 defensive involvements. Corresponds to jersey number 5. +Alejandro Garnacho: 8 goals, 7 points in speed, 8 points in assists, 6 points in passing accuracy, 0 defensive involvements. Corresponds to jersey number 17. +Mason Mount: 2 goals, 6 points in speed, 4 points in assists, 8 points in passing accuracy, 1 defensive involvement. Corresponds to jersey number 7. +The program functions as follows: The coach accesses the system and encounters a menu with the following options: + +Player Review: By entering the player's jersey number, they can access the player's characteristics. +Compare two players: The system prompts for two jersey numbers and displays the data of both players on screen. +Identify the fastest player: Displays the player with the most points in speed. +Identify the top goal scorer: Displays the player with the most points in goals. +Identify the player with the most assists: Displays the player with the most points in assists. +Identify the player with the highest passing accuracy: Displays the player with the most points in passing accuracy. +Identify the player with the most defensive involvements: Displays the player with the most points in defensive involvements. +The system should also allow returning to the main menu. +*/ + +#include +#include +#include +//Player "object" with all the characteristics +typedef struct player{ + char name[40]; + int goals; + int speed; + int assists; + int passing_accuracy; + int defensive_involvemnt; + int jersey_number; +}player; + +//Procedure to display the characteristic of a specific player +void display_player(int index, player * list){ + printf("\nThe player:%s\nGoals:%i\nSpeed:%i\nAssists:%i\nPassing accurecy:%i\nDefensive involvement:%i\n\n",list[index].name,list[index].goals,list[index].speed,list[index].assists,list[index].passing_accuracy,list[index].defensive_involvemnt); +} + +int main(){ + player players[5]; + //First player + strcpy(players[0].name , "Bruno Fernandez"); + players[0].goals = 5; + players[0].speed = 6; + players[0].assists = 9; + players[0].passing_accuracy = 10; + players[0].defensive_involvemnt = 3; + players[0].jersey_number = 8; + //Second player + strcpy(players[1].name , "Rasmus Hojlund"); + players[1].goals = 12; + players[1].speed = 8; + players[1].assists = 2; + players[1].passing_accuracy = 6; + players[1].defensive_involvemnt = 2; + players[1].jersey_number = 11; + //Third player + strcpy(players[2].name, "Harry Maguire"); + players[2].goals = 1; + players[2].speed = 5; + players[2].assists = 1; + players[2].passing_accuracy = 7; + players[2].defensive_involvemnt = 9; + players[2].jersey_number = 5; + //forth player + strcpy(players[3].name,"Alejandro Garnacho" ); + players[3].goals = 8; + players[3].speed = 7; + players[3].assists = 8; + players[3].passing_accuracy = 6; + players[3].defensive_involvemnt = 0; + players[3].jersey_number = 17; + //fith player + strcpy(players[4].name,"Mason Mount"); + players[4].goals = 5; + players[4].speed = 6; + players[4].assists = 4; + players[4].passing_accuracy = 8; + players[4].defensive_involvemnt = 1; + players[4].jersey_number = 7; + + int menu = 1; + int option; + int jersey_option; + int jersey_option2; + int aux; + int index1; + int index2; + int index_top; + int error_flag; + int exit_option; + while(menu==1){ + //Display a player with his jersey number + printf("MENU:\n1-Player review\n2-Compare two players\n3-Identify de fastest player\n4-Identify the top goal scorer\n"); + printf("5-Identify the player with most assists\n6-Identify the player with the highest passing accurency\n7-Display the player with the most defensive involment\n8-Exit\n\n"); + scanf("%i",&option); + index_top=0; + switch(option){ + case 1: + error_flag = 0; + printf("\nEnter the jersey number of the player(8,11,5,17,7):"); + scanf("%i",&jersey_option); + for(int i = 0; i < 5; i++){ + if(players[i].jersey_number==jersey_option){ + display_player(i,players); + error_flag = 1; + break; + } + } + if(error_flag == 0){ + printf("Incorrect jersey number\n"); + } + printf("\nDo you want to exit?\n1-Exit\n2-Return to the Menu\n\n"); + scanf("%i",&exit_option); + if(exit_option!=2){ + menu = 0; + } + break; + //Display or "compare" two players with their jersey number + case 2: + aux = 0; + printf("Please enter the jersey number of the first player:"); + scanf("%i",&jersey_option); + printf("Now enter the jersey number of the second player:"); + scanf("%i",&jersey_option2); + printf("First player:\n"); + for(int i = 0; i < 5;i++){ + if(players[i].jersey_number==jersey_option){ + index1 = i; + aux++; + } + if(players[i].jersey_number == jersey_option2){ + index2 = i; + aux++; + } + } + if(aux == 2){ + display_player(index1,players); + printf("\n"); + display_player(index2,players); + }else{ + printf("Incorrect Jersey number, try again\n"); + } + printf("\nDo you want to exit?\n1-Exit\n2-Return to the Menu\n\n"); + scanf("%i",&exit_option); + if(exit_option!=2){ + menu = 0; + } + break; + //Show the fastest player + case 3: + for(int i = 1; i < 4; i++){ + if(players[index_top].speed +#include +#include + + +//I don't have much time so this algorithm will be simpler than the other ones + +int main(){ + int menu = 1; + int menu_option; + int account_flag = 0; + int log_in_flag=0; + int origin_country; + int destiny_country; + int log_in_counter = 0; + int last_flag = 0; + int year; + int month; + int day; + int days; + int return_day; + int return_month; + int return_year; + int condition; + char * conditions[]={"Economy","First class"}; + char * ptruser_username; + char * ptruser_password; + char * ptraux_username; + char * ptraux_password; + char * countries[]={"Turkey","Greece","Lebanon","Spain","Portugal"}; + int meal_option; + char * meals[]={"Regular","Vegetarian","Kosher"}; + int additional_luggage; + char * luggage_options[]={"Yes","No"}; + char * name; + char * id; + int final_response; + while(menu == 1){ + //Menu + printf("Turkish Airlines Menu, choose an option\n\n1-Create an account\n2-Log in and buy tickets\n3-Exit\n\n"); + scanf("%i",&menu_option); + switch (menu_option){ + //Creating an account + case 1: + if(account_flag==0){ + ptruser_username = malloc(sizeof(char)); + ptruser_password = malloc(sizeof(char)); + printf("Creating a new Account , please enter a new username:"); + scanf("%s",ptruser_username); + printf("Now enter your new password:\n"); + scanf("%s",ptruser_password); + printf("Account created successfuly\n\n"); + account_flag=1; + }else{ + printf("You already created an Account\n\n"); + } + break; + case 2: + //Log in + if(account_flag==1){ + ptraux_username = malloc(sizeof(char)); + ptraux_password = malloc(sizeof(char)); + printf("To continue please enter your Credentials\nUsername:"); + scanf("%s",ptraux_username); + printf("Now enter the password:"); + scanf("%s",ptraux_password); + //Validating credentials + if( 0 == strcmp(ptruser_username, ptraux_username) && 0 == strcmp(ptruser_password,ptraux_password)){ + printf("Log in Successful\nNow please choose an Origin Country\n\n"); + log_in_flag = 1; + for(int i = 0; i < 5; i++){ + printf("%i-%s\n",i+1,countries[i]); + } + //Origin country + scanf("%i",&origin_country); + if(origin_country>0 && origin_country<6){ + printf("Now please select a destiny country:\n\n"); + for(int i = 0; i < 5; i++){ + if(0 == strcmp(countries[i],countries[origin_country-1])){ + + continue; + } + printf("%i-%s\n",i+1,countries[i]); + } + //Destiny country + scanf("%i",&destiny_country); + if(destiny_country<6 && destiny_country>0){ + //Date of the fly + printf("Now please enter the date of the flight\nYear(number):"); + scanf("%i",&year); + printf("Month:"); + scanf("%i",&month); + printf("Day:"); + scanf("%i",&day); + if(year>=2024 && month>0 && month<13 && day>0 && day <31){ + //Condition of the seat + printf("\n\nSelect a condition:\n1-Economy\n2-VIP\n\n"); + scanf("%i",&condition); + if(condition>0 && condition<3){ + //Additional luggage + printf("Do you want to check an additional piece of luggage?(It has an additional cost):\n1-Yes\n2-No\n"); + scanf("%i",&additional_luggage); + if(additional_luggage>0 && additional_luggage<3){ + //Meal Type + printf("What type of meal do you prefer?:\n1-Regular\n2-Vegetarian\n3-Kosher\n"); + scanf("%i",&meal_option); + if(meal_option>0 && meal_option<4){ + //Calculating the return fly date + printf("\nHow long do you plan to stay?(number of days):"); + scanf("%i",&days); + return_day = day; + return_month = month; + return_year = year; + if(return_day + days > 31){ + return_day = (return_day + days) % 31; + if(return_day==0){ + return_day++; + } + if(return_month == 12){ + return_month = 1; + return_year++; + }else{ + month++; + } + }else{ + return_day =return_day + days; +; } + last_flag = 1; + name = malloc(sizeof(char)); + id = malloc(sizeof(char)); + //Asking personal info + printf("\nNow please enter your name:"); + scanf("%s",name); + printf("\nEnter your passport number:"); + scanf("%s",id); + //Showing all the choices + printf("\nFINAL PREVIEW\n\nName:%s\nPassport:%s\nOutbound ticket: Origin country:%s Destination country:%s\nDate(month/day/year):%i/%i/%i",name,id,countries[origin_country-1],countries[destiny_country-1],month,day,year); + printf("\nReturn ticket: Origin country:%s Destiny country:%s\nDate(month/day/year):%i/%i/%i\n\n",countries[destiny_country-1],countries[origin_country-1],return_month,return_day,return_year); + printf("Additional luggage: %s\n Meal type:%s",luggage_options[additional_luggage-1],meals[meal_option-1]); + printf("Do you agree with this ?:\n1-Yes\n2-No\n"); + scanf("%i",&final_response); + //Final choiche + switch (final_response){ + case 1: + printf("\n\nCongratulations"); + menu=0; + break; + case 2: + break; + default: + printf("Invalid option\n\n"); + break; + } + }else{ + printf("Invalid option\n\n"); + } + }else{ + printf("Invalid option\n\n"); + } + }else{ + printf("invalid option\n\n"); + } + }else{ + printf("Invalid date\n\n"); + } + }else{ + printf("Invalid option\n\n"); + } + }else{ + printf("Invalid option\n\n"); + } + }else{ + printf("Wrong credentials\n\n"); + log_in_counter++; + if(log_in_counter==3){ + printf("To many attempts, Locking the system"); + menu=0; + } + } + break; + }else{ + printf("Please create an Account\n\n"); + } + default: + menu=0; + break; + } + } + //Freing memory + if(account_flag==1){ + free(ptruser_password); + free(ptruser_username); + } + if(log_in_flag == 1){ + free(ptraux_password); + free(ptraux_username); + } + if(last_flag==0){ + free(name); + free(id); + } + return 0; +} \ No newline at end of file