nitroman84
Technical User
Hello, I'm racking my brain here. I have been self teaching fortran for some time now and this is the program I use for practice. In my practice program I am asking for an input of 0 or 1 as a yes or no answer to continue execution and any other # will give an error message. My question is how to expand this to include letters a-z as also giving an error message? As my code stands I just get a runtime error if a letter is accidentally entered.
Here is the source code...
Program Practice
Implicit None
Character :: Uname*25, Uage*3, Ustate*25
Integer :: Uanswer1, Uanswer2
Call System ("title My Practice Program && mode 50,20 && color 80")
Print "(a,/)", 'Enter your name, age and state'
Print "(/,a,/,/,a,/,a)", 'Continue ?', 'Type 1 to continue', &
'Type 0 to exit program'
Read *, Uanswer1
Do
Do
If (Uanswer1 >= 2) Then !<--- this if statement is the code in question.
Call System ('title Error! && mode 20,5 && color ce')
Print "(/,/,a,/,/,a,/,a)", 'Error!','Type 1 to continue', 'Type 0 to exit'
Read *, Uanswer1
Else
Call System ('title My Practice Program && mode 50,20 && color 80 ')
Exit
End If
End Do
If (Uanswer1 == 0) Then
Exit
Else If (Uanswer1 == 1) Then
Continue
Else
Exit
End If
Open(10, File = 'C:\Users\Public\Desktop\Output.txt', Status = 'Unknown')
Print "(/,/,a)", 'Enter name'
Read *, Uname
Print "(/,a)", 'Enter age'
Read *, Uage
Print "(/,a)", 'Enter state'
Read *, Ustate
Write(10, *) " "
Write(10, *) " Name : ", Uname
Write(10, *) " Age : ", Uage
Write(10, *) " State : ", Ustate
Write(10, *) " ________________________________ "
Print "(/,/,a)", 'Enter another?'
Read *, Uanswer2
Do
If (Uanswer2 >= 2) Then
Call System ('title Error! && mode 20,5 && color ce')
Print "(/,/,a,/,/,a,/,a)", 'Error!','Type 1 to continue', 'Type 0 to exit'
Read *, Uanswer2
Else
Call System ('title My Practice Program && mode 50,20 && color 80 ')
Exit
End If
End Do
If (Uanswer2 == 0) Then
Exit
Else If (Uanswer2 == 1) Then
Continue
Else
Exit
End If
End Do
Close(10)
If (Uanswer1 == 0) Then
Print "(/,/,a,/,/,a)", 'Program was stopped before execution', &
'Press Enter to exit'
Else If (Uanswer1 == 1) Then
Call System ('C:\Users\Public\Desktop\Output.txt')
Print "(/,/,a,/,/,a)", 'Results have been written to "Output.txt"', &
'Press Enter to exit'
End If
Read *,
End Program Practice
Any help would be much appreciated.
Here is the source code...
Program Practice
Implicit None
Character :: Uname*25, Uage*3, Ustate*25
Integer :: Uanswer1, Uanswer2
Call System ("title My Practice Program && mode 50,20 && color 80")
Print "(a,/)", 'Enter your name, age and state'
Print "(/,a,/,/,a,/,a)", 'Continue ?', 'Type 1 to continue', &
'Type 0 to exit program'
Read *, Uanswer1
Do
Do
If (Uanswer1 >= 2) Then !<--- this if statement is the code in question.
Call System ('title Error! && mode 20,5 && color ce')
Print "(/,/,a,/,/,a,/,a)", 'Error!','Type 1 to continue', 'Type 0 to exit'
Read *, Uanswer1
Else
Call System ('title My Practice Program && mode 50,20 && color 80 ')
Exit
End If
End Do
If (Uanswer1 == 0) Then
Exit
Else If (Uanswer1 == 1) Then
Continue
Else
Exit
End If
Open(10, File = 'C:\Users\Public\Desktop\Output.txt', Status = 'Unknown')
Print "(/,/,a)", 'Enter name'
Read *, Uname
Print "(/,a)", 'Enter age'
Read *, Uage
Print "(/,a)", 'Enter state'
Read *, Ustate
Write(10, *) " "
Write(10, *) " Name : ", Uname
Write(10, *) " Age : ", Uage
Write(10, *) " State : ", Ustate
Write(10, *) " ________________________________ "
Print "(/,/,a)", 'Enter another?'
Read *, Uanswer2
Do
If (Uanswer2 >= 2) Then
Call System ('title Error! && mode 20,5 && color ce')
Print "(/,/,a,/,/,a,/,a)", 'Error!','Type 1 to continue', 'Type 0 to exit'
Read *, Uanswer2
Else
Call System ('title My Practice Program && mode 50,20 && color 80 ')
Exit
End If
End Do
If (Uanswer2 == 0) Then
Exit
Else If (Uanswer2 == 1) Then
Continue
Else
Exit
End If
End Do
Close(10)
If (Uanswer1 == 0) Then
Print "(/,/,a,/,/,a)", 'Program was stopped before execution', &
'Press Enter to exit'
Else If (Uanswer1 == 1) Then
Call System ('C:\Users\Public\Desktop\Output.txt')
Print "(/,/,a,/,/,a)", 'Results have been written to "Output.txt"', &
'Press Enter to exit'
End If
Read *,
End Program Practice
Any help would be much appreciated.