[c programming] - Computers



Search Tech-Forums - link takes you to our Forum's search page.

Note: The following is only a text archive!


To view the actual forum discussion, please visit our website at http://www.tech-forums.net

Pages:1



c programming

(Click here to view the original thread with full colors/images)



Posted by: JinkX

heres the probliem ..
if i enter an alpha in this program all i will have is an endless loop
what can i do to stop this ?? and print the statement "what ever"
here the program

#include <stdio.h>
int main ()
{
// here u enter the 3 integers of time
int hrs , min , sec ;

printf("please enter the hrs now\n");
scanf("%d",&hrs);
// if the time was wrong this will make u inter the number again
while (hrs <0 || hrs >=24 )

{
printf("this time is invalid please enter a valid number\n");
scanf("%d",&hrs);

}
printf("please enter min now\n");
scanf ("%d",&min);
while (min < 0 || min > 60)
{
printf("this time is invalid please enter a valid number\n");
scanf("%d",&min);
}
printf("please enter sec now\n");
scanf("%d",&sec);
while (sec < 0|| sec >= 60 )
{
printf("this time is invalid please enter a valid number\n");

scanf("%d",&sec);
}
// if evrything is going ok , then the output will be as the following
printf("the time is %02d : %02d : %02d ",hrs,min,sec);


return 0;
}





vBulletin Copyright ©2000 - 2003, Jelsoft Enterprises Limited.


PPC Management
vB Easy Archive Final - Created by Xenon