- sum is the name of a function. Replace sum by sumScore
- doesn't the code behave as you expect?
Info
This question is closed. Reopen it to edit or answer.
Kindly tell me what should I change to correct my script?
1 view (last 30 days)
Show older comments
Write a program that asks the user to enter test scores (1 by 1) using a loop. The number of scores is unknown so keep prompting the user for scores until the user enters -1. We call this the termination condition. Round off all the scores to the nearest integer. Calculate the sum, mean, standard deviation, mode, median, maximum, minimum and range of the scores entered.
MY SCRIPT:
score= input('Enter test score(enter <0 to quit):');
roundOff = round(score);
sum=0;
meanScore= mean(sum)
stddevScore= std(sum)
modeScore= mode(sum)
medianScore= median(sum)
minScore= min(sum);
while (score >=0)
roundOff=round(score)
score= input('Enter test score(enter <0 to quit):');
sum=sum + score
meanScore= mean(sum)
stddevScore= std(sum)
modeScore= mode(sum)
medianScore= median(sum)
minScore= min(sum)
score= input('Enter test score(enter <0 to quit):');
end
1 Comment
per isakson
on 29 Jan 2015
Edited: per isakson
on 29 Jan 2015
Answers (1)
Image Analyst
on 29 Jan 2015
Don't use sum, either as a variable or a function. Index the arrays in the loop, for example
medianScores(loopCounter) = score;
At the end of the loop
loopCounter = LoopCOunter + 1;
and of course set it to 1 before the loop starts. Then calculate all the stats after the loop exits, for example:
medianScore = median(medianScores);
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!