Sponsored Content
Top Forums Programming Problem with IF ELSEIF and GOTO statements in FORTRAN Post 302881471 by faizlo on Sunday 29th of December 2013 12:43:04 PM
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..
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
WRITE(1)						     Linux Programmer's Manual							  WRITE(1)

NAME
write - send a message to another user SYNOPSIS
write user [ttyname] DESCRIPTION
Write allows you to communicate with other users, by copying lines from your terminal to theirs. When you run the write command, the user you are writing to gets a message of the form: Message from yourname@yourhost on yourtty at hh:mm ... Any further lines you enter will be copied to the specified user's terminal. If the other user wants to reply, they must run write as well. When you are done, type an end-of-file or interrupt character. The other user will see the message EOF indicating that the conversation is over. You can prevent people (other than the super-user) from writing to you with the mesg(1) command. Some commands, for example nroff(1) and pr(1), may disallow writing automatically, so that your output isn't overwritten. If the user you want to write to is logged in on more than one terminal, you can specify which terminal to write to by specifying the ter- minal name as the second operand to the write command. Alternatively, you can let write select one of the terminals - it will pick the one with the shortest idle time. This is so that if the user is logged in at work and also dialed up from home, the message will go to the right place. The traditional protocol for writing to someone is that the string `-o', either at the end of a line or on a line by itself, means that it's the other person's turn to talk. The string `oo' means that the person believes the conversation to be over. SEE ALSO
mesg(1), talk(1), who(1) HISTORY
A write command appeared in Version 6 AT&T UNIX. AVAILABILITY
The write command is part of the util-linux-ng package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/. 12 March 1995 WRITE(1)
All times are GMT -4. The time now is 12:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy