so I have this program that asks a user to enter a time(24 hour clock) and spit out the next available flight. the program works except for one thing: I've tried to get it to loop until a user chooses to quit (giving the variable <int action> a value of 2) but no matter the value of <action> the program terminates. Am I not looping this correctly? Here's the code:
// lab3q8.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <process.h>
//variables
int user_h,user_m,air_h,air_m,action;
//boolean operator (checks the user input for validity)
bool _valid;
//main program
int main(void)
{
//printf("TP1");
while (_valid==true);
{
//printf("TP2");
//system("clear");//clears screen upon each program loop
printf("Please enter a time (24 hour clock) in the following format (hh:mm)");
scanf_s("%d:%d", &user_h, &user_m);
if ((user_h<=24&&user_h>=0)&&(user_m>=0||user_m<=60))//this if statement checks if the user input is valid
{
if (user_h<=8)//this if statement determines the output
printf("The next available flight:\nDeparture\tArrival\n8:00a.m.\t10:16a.m.");
else if (user_h<=9&&user_m<43)
printf("The next available flight:\nDeparture\tArrival\n9:43a.m.\t11:52a.m.");
else if (user_h<=11&&user_m<19)
printf("The next available flight:\nDeparture\tArrival\n11:19a.m.\t1:31a.m.");
else if (user_h<=12&&user_m<47)
printf("The next available flight:\nDeparture\tArrival\n12:47p.m.\t3:00p.m.");
else if (user_h<2)
printf("The next available flight:\nDeparture\tArrival\n2:00p.m.\t4:08p.m.");
else if (user_h<=3&&user_m<45)
printf("The next available flight:\nDeparture\tArrival\n3:45p.m.\t5:55p.m.");
else if (user_h<7)
printf("The next available flight:\nDeparture\tArrival\n7:00p.m.\t9:20p.m.");
else if (user_h<=9&&user_m<45)
printf("The next available flight:\nDeparture\tArrival\n9:45p.m.\t11:58p.m.");
else
printf("I'm sorry, but you have missed all available flight times for today; please try again tomorrow morning");
printf("Would you like to run this program again?, key \"1\" for yes and \"2\" for no");
scanf_s("%d", &action);
if (action=2)
_valid = false;
else
_valid = true;
}
else
{
printf("Please enter a valid format/time, please execute this program again");
_valid==false;
system("PAUSE");
}
}
return 0;
}
// lab3q8.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <process.h>
//variables
int user_h,user_m,air_h,air_m,action;
//boolean operator (checks the user input for validity)
bool _valid;
//main program
int main(void)
{
//printf("TP1");
while (_valid==true);
{
//printf("TP2");
//system("clear");//clears screen upon each program loop
printf("Please enter a time (24 hour clock) in the following format (hh:mm)");
scanf_s("%d:%d", &user_h, &user_m);
if ((user_h<=24&&user_h>=0)&&(user_m>=0||user_m<=60))//this if statement checks if the user input is valid
{
if (user_h<=8)//this if statement determines the output
printf("The next available flight:\nDeparture\tArrival\n8:00a.m.\t10:16a.m.");
else if (user_h<=9&&user_m<43)
printf("The next available flight:\nDeparture\tArrival\n9:43a.m.\t11:52a.m.");
else if (user_h<=11&&user_m<19)
printf("The next available flight:\nDeparture\tArrival\n11:19a.m.\t1:31a.m.");
else if (user_h<=12&&user_m<47)
printf("The next available flight:\nDeparture\tArrival\n12:47p.m.\t3:00p.m.");
else if (user_h<2)
printf("The next available flight:\nDeparture\tArrival\n2:00p.m.\t4:08p.m.");
else if (user_h<=3&&user_m<45)
printf("The next available flight:\nDeparture\tArrival\n3:45p.m.\t5:55p.m.");
else if (user_h<7)
printf("The next available flight:\nDeparture\tArrival\n7:00p.m.\t9:20p.m.");
else if (user_h<=9&&user_m<45)
printf("The next available flight:\nDeparture\tArrival\n9:45p.m.\t11:58p.m.");
else
printf("I'm sorry, but you have missed all available flight times for today; please try again tomorrow morning");
printf("Would you like to run this program again?, key \"1\" for yes and \"2\" for no");
scanf_s("%d", &action);
if (action=2)
_valid = false;
else
_valid = true;
}
else
{
printf("Please enter a valid format/time, please execute this program again");
_valid==false;
system("PAUSE");
}
}
return 0;
}