Problem with IF ELSEIF and GOTO statements in FORTRAN


 
Thread Tools Search this Thread
Top Forums Programming Problem with IF ELSEIF and GOTO statements in FORTRAN
# 1  
Old 12-29-2013
Problem with IF ELSEIF and GOTO statements in FORTRAN

Hi

I am reading a book about Fortran 90 and I write the following code, to test my understanding of the first chapter. I have a problem with the last section of the code with deals with an IF, ELSEIF, and GOTO statements. Here is my Code

Code:
PROGRAM sim 
! This code is used to solve two simultaneous 
! equations in two variables with real coefficients: 
! 
!   DATE:        DEVELOPER:              CHANGES: 
!  ------       -----------             ---------- 
!  12/28/13     Faiz Lo                 Original Code 
! 
IMPLICIT NONE  
! Dictionary Data: Declare variables 
REAL :: x, y, a1, b1, a2, b2, c1, c2 
CHARACTER :: Ans  
! Salut message 
WRITE (*,*) '**************************************' 
WRITE (*,*) '*                                    *' 
WRITE (*,*) '* This code is used to solve two     *' 
WRITE (*,*) '* simultaneous equations in two      *' 
WRITE (*,*) '* variables of the form              *' 
WRITE (*,*) '* a1*x + b1*y = c1,                  *' 
WRITE (*,*) '* a2*x + b2*y = c2.                  *' 
WRITE (*,*) '*                                    *' 
WRITE (*,*) '**************************************'  
! Ask the user for inputs 
100 WRITE (*,*) '' 
WRITE (*,*) ' Please enter a1:' 
READ (*,*) a1 
WRITE (*,*) ''
WRITE (*,*) ' Please enter b1:' 
READ (*,*) b1 
WRITE (*,*) '' 
WRITE (*,*) ' Please enter c1:' 
READ (*,*) c1 
WRITE (*,*) '' 
WRITE (*,*) ' Please enter a2:' 
READ (*,*) a2 
WRITE (*,*) '' 
WRITE (*,*) ' Please enter b2:' 
READ (*,*) b2 
WRITE (*,*) '' 
WRITE (*,*) ' Please enter c2:' 
READ (*,*) c2 
WRITE (*,*) ''  
! calculations 
x = ( (b2*c1) - (b1*c2) ) / ( a1*b2 - a2*b1 ) 
y = ( (a2*c1) - (a1*c2) ) / ( a2*b1 - a1*b2 )  
! Write the answers  
WRITE (*,*) ' The value of "x" is:', x 
WRITE (*,*) ' The value of "y" is:', y 
WRITE (*,*) ''  
! Do you want to try again? 
WRITE (*,*) ' Do you want to solve another pair ' 
101 WRITE (*,*) ' Please answer yes or no' 

READ (*,*) Ans    
IF (Ans == "yes") THEN     
GOTO 100   

ELSEIF (Ans == "no") THEN     
WRITE (*,*) ' Good Bye!'   

ELSE     
GOTO 101   

ENDIF  

STOP 
END PROGRAM sim

I would appreciate any help in pointing out the bug in this code.

~faizlo

Last edited by faizlo; 12-29-2013 at 04:30 PM..
# 2  
Old 12-29-2013
Quote:
Originally Posted by faizlo
Hi

I am reading a book about Fortran 90 and I write the following code, to test my understanding of the first chapter. I have a problem with the last section of the code with deals with an IF, ELSEIF, and GOTO statements. Here is my Code

Code:
PROGRAM sim 
! This code is used to solve two simultaneous 
! equations in two variables with real coefficients: 
! 
!   DATE:        DEVELOPER:              CHANGES: 
!  ------       -----------             ---------- 
!  12/28/13     Faiz Lo                 Original Code 
! 
IMPLICIT NONE  
! Dictionary Data: Declare variables 
REAL :: x, y, a1, b1, a2, b2, c1, c2 
CHARACTER :: Ans  
! Salut message 
WRITE (*,*) '**************************************'

Hai Faizlo, everything is alright except variable declaration for char

make like this and run it should work

Code:
CHARACTER(LEN=3) Ans

This User Gave Thanks to Akshay Hegde For This Post:
# 3  
Old 12-29-2013
YES!
I knew I was missing something!
It works now!

Thank you so much!

~faizlo

Last edited by faizlo; 12-29-2013 at 08:06 PM..
# 4  
Old 12-29-2013
All the very best !
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

A dash to GOTO or a dash from GOTO, that is the question...

Well, guys I saw a question about GOTO for Python. So this gave me the inspiration to attempt a GOTO function for 'dash', (bash and ksh too). Machine: MBP OSX 10.14.3, default bash terminal, calling '#!/usr/local/bin/dash'... This is purely a fun project to see if it is possible in PURE... (3 Replies)
Discussion started by: wisecracker
3 Replies

2. Programming

FORTRAN:Algortihmic Problem

Hi guys I am faced with this problem that I couldn't figure out yet, if you can point me to some direction that'll be of great help. So here's what I want to do. I have let's say 10000 files which contains same number of Z coordinates in each file. I have to find the distance of those... (6 Replies)
Discussion started by: saleheen
6 Replies

3. Programming

Removing goto statements in FORTRAN code

I have the code below and I want to remove the "go to" statements. Any idea how I can do it? if (iorder == 0) then tmincurrent = 1.0e11 if(ireverse == 0 .or. istop /= 1) then do i = 1, 6 if ((side(i) /= sidelimit(i)) .and. (tminside(i) < tmincurrent)) then ... (1 Reply)
Discussion started by: kristinu
1 Replies

4. Linux

Fortran compile problem

Hello everyone, I am trying to compile a code under fedora14.Kernel Linux 2.6.35.6-45fc14.i686-GNOME 2.32.0. I use f77,g77 and gfortran to compile but I get the same error all ways. Unsupported OPEN control item at (^) -- ACTION=, ASSOCIATEVARIABLE=, BLOCKSIZE=, BUFFERCOUNT=,... (1 Reply)
Discussion started by: miriammiriam
1 Replies

5. Shell Programming and Scripting

Multiple If statements in bash problem

Hi everyone, May you help me with the correct syntax of the follow bash statements please X=10 if ]; then echo "The value is between 1 and 5" for ((i=1;i<=${X})); do echo $i done else if ]; then echo "The value is between 6 and 10" for ((i=1;i<=${X})); do ... (5 Replies)
Discussion started by: Ophiuchus
5 Replies

6. Shell Programming and Scripting

if elseif fi

Hi, Ihave shifted this thread which i posted in linux forum to here if i am fault please correct me. When i excute this below script i am getting the follwing error can any one please look into it for persual. ./sample_oracle_tradescope.sh: 25: showDEFAULTUsage: not found ... (6 Replies)
Discussion started by: oracle_coorgi
6 Replies

7. Linux

if elseif fi

Hi all, This is my first post in this forum, can i request you to guide, where i am going wrong with the error below. 34: Syntax error: "fi" unexpected (expecting "then") #!/bin/sh argCount=0 mysql_path=$USER_INSTALL_DIR$ for i in $*; do /A argCount+=1 done if ;then echo... (2 Replies)
Discussion started by: oracle_coorgi
2 Replies

8. Shell Programming and Scripting

elseif in csh

I have been using the if statement in csh like this if ( $opt1 == 1 ) then ..... elseif ( $opt2 == 1 ) then ...... endif Seems to work, but got Badly placed ()'s. When I used a space in the elseif, a space between the 'else' and the 'if' it worked (0 Replies)
Discussion started by: kristinu
0 Replies

9. Shell Programming and Scripting

Problem with my case statements

Hi there, Im having some problems with this function, I pass two arguments to the function $1 $2 (Arguments are month and date inputted by the user) for some reason the case always fails... however in the cases defined below where it shouldnt fail the result is: if it fails with input... (6 Replies)
Discussion started by: Darklight
6 Replies
Login or Register to Ask a Question