Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
208 changes: 208 additions & 0 deletions appointment_app.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <string.h>

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;
}
114 changes: 114 additions & 0 deletions best_destination.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <string.h>
//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;
}
Loading