Need help

New to FreeBASIC? Post your questions here.
Post Reply
Burning Lamp
Posts: 4
Joined: Feb 13, 2018 21:14

Need help

Post by Burning Lamp »

Hi, I am a very new FreeBasic programmer and experiencing an issue which is probably easily fixable... I am making an average and sum calculator, and having trouble making the running total & max number inputted to work. The answers keep coming up as 0.

Code: Select all

dim scores(20) as integer
dim i as integer
dim sumscore(20) as integer
dim sumruntotal as integer
dim sumtotal as integer
dim sum as integer
dim average as integer
dim runningtotal as integer
dim max as integer

i = 1
runningtotal = 0
max = 0
do
    print "Enter a score"
    input scores(i)
    i = i + 1
    runningtotal = runningtotal + scores(i)
    print "The running total is", runningtotal
    if scores(i) > max then max = scores(i)
    print "The max score is", max
loop until i > 5

i = 1
print "Your scores are:"
do
    print scores (i);
    i = i + 1
    print 
loop until i > 5

i = 1
sumtotal = 0
do
    sumscore(i) = scores(i)
    sumruntotal = sumscore(i)
    sumtotal = sumtotal + sumruntotal
    i = i + 1
loop until i > 5
print "The sum of the scores are"; sumtotal; "."
print "The average of the scores are"; sumtotal /5
sleep
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: Need help

Post by speedfixer »

move the i = i + 1 in the first loop to just before the loop statment
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: Need help

Post by srvaldez »

maybe this is what you want

Code: Select all

dim scores(20) as integer
dim i as integer
dim sumscore(20) as integer
dim sumruntotal as integer
dim sumtotal as integer
dim sum as integer
dim average as integer
dim runningtotal as integer
dim max as integer

i = 1
runningtotal = 0
max = 0
do
    print "Enter a score"
    input scores(i)
    ''i = i + 1 moved to just before loop end
    runningtotal = runningtotal + scores(i)
    print "The running total is", runningtotal
    if scores(i) > max then max = scores(i)
    print "The max score is", max
    i = i + 1
loop until i > 5

i = 1
print "Your scores are:"
do
    print scores (i);
    i = i + 1
    print 
loop until i > 5

i = 1
sumtotal = 0
do
    sumscore(i) = scores(i)
    sumruntotal = sumscore(i)
    sumtotal = sumtotal + sumruntotal
    i = i + 1
loop until i > 5
print "The sum of the scores are"; sumtotal; "."
print "The average of the scores are"; sumtotal /5
Burning Lamp
Posts: 4
Joined: Feb 13, 2018 21:14

Re: Need help

Post by Burning Lamp »

Hello, thanks for helping me out. I actually managed to figure it out in class a couple of days ago and made it a bit better. Here it is if you want to look at it.

Code: Select all

dim scores(30) as integer
dim i as integer
dim sumscore(30) as integer
dim sumruntotal as integer
dim sumtotal as integer
dim sum as integer
dim average as integer
dim runningtotal as integer
dim max as integer
dim min as integer

i = 1
runningtotal = 0

do
    print "Enter a score"
    input scores(i)
    if i = 1 then max = scores(i)
    if i = 1 then min = scores(i)
    if min > scores(i) then min = scores(i)
    print "The min score is", min    
    if scores (i) > max then max = scores(i)
    print "The max score is", max 
    runningtotal = runningtotal + scores(i)
    print "The running total is", runningtotal
    i = i + 1
loop until i > 5

i = 1
print "Your scores are:"
do
    print scores (i);
    i = i + 1
    print 
loop until i > 5

i = 1
sumtotal = 0
do
    sumscore(i) = scores(i)
    sumruntotal = sumscore(i)
    sumtotal = sumtotal + sumruntotal
    i = i + 1
loop until i > 5
print "The sum of the scores are"; sumtotal; "."
print "The average of the scores are"; sumtotal /5
print "The maximum number inputted was"; max
print "The minimum number inputted was"; min
sleep
Post Reply