Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with arithmetic program result.

Status
Not open for further replies.

Dukelord123

Technical User
Nov 27, 2010
4
DE
Ok, so I am new to FOTRAN and after installation, got it to work. I use MinGW. Now I try compiling a program and it compiles and runs. However the result is weird. See source code and result below. I get **** as answer. Can someone pls tell me what I am missing. Thanks and regards.

PROGRAM SUMNUM
INTEGER SUM,COUNTER,A
COUNTER=0
SUM=O
5 READ(*,*)A
SUM=SUM+A
COUNTER=COUNTER+1
IF (COUNTER .LT. 10) GOTO 5
WRITE(*,10)SUM
10 FORMAT(/,'THE SUM OF ALL TEN NUMBERS=',1X,I4)
STOP
END

The result below.

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

D:\Postgraduate\Programming\FORTRAN>gfortran first.f

D:\Postgraduate\Programming\FORTRAN>a.exe
1
2
3
4
5
6
7
8
9
0

THE SUM OF ALL TEN NUMBERS= ****

D:\Postgraduate\Programming\FORTRAN>
 
you have typo:
On the beginning change SUM=O to SUM=0 (i.e. change O to zero)
Then it works:
Code:
$ g77 sumnum.for -o sumnum

$ sumnum
1
2
3
4
5
6
7
8
9
10

THE SUM OF ALL TEN NUMBERS=   55
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top