Concept explainers
Hi I need help please the code is not calculating the average correctly
for example, I entered 4 integers, '5', '4', '3', '8',
and it resulted that the average is 2, which is incorrect
this is the code:
.data
prompt1: .asciiz "Enter the number of real numbers: "
prompt2: .asciiz "Enter a real number: "
result: .asciiz "The average is: "
.text
.globl main
main:
# Prompt for the number of real numbers
li $v0, 4
la $a0, prompt1
syscall
li $v0, 5
syscall
move $t0, $v0
move $t1, $zero
# Initialize floating-point sum to 0.0
li $t2, 0
mtc1 $t2, $f0
cvt.s.w $f0, $f0
input_loop:
beq $t1, $t0, calculate
# Prompt for each real number
li $v0, 4
la $a0, prompt2
syscall
li $v0, 6
syscall
add.s $f0, $f0, $f12
addi $t1, $t1, 1
j input_loop
calculate:
# Calculate the average
mtc1 $t0, $f2
cvt.s.w $f2, $f2
div.s $f4, $f0, $f2
# Print the result
li $v0, 4
la $a0, result
syscall
mov.s $f12, $f4
li $v0, 2
syscall
# Exit program
li $v0, 10
syscall
Step by stepSolved in 2 steps
- Part: 6 Please answer the ques in Python with showing the code.Answeer the ques ASAParrow_forwardS1 = 'abcdefgh' %3D S2 = S1 S1 = S1.replace('b', 'k') The value of the expression S1 == S2 is O True O Falsearrow_forwardProgram Purpose - Professional Athletes often hire other professionals to help take care of matters for them. We will group them in four categories: Lawyers, Personal Assistants, Agents, and Trainers. They all get paid a percentage of the athlete's total yearly salary. Lawyers - 10%, Personal Assistants - 3%, Agents - 7%, and Trainers - 5% . Prompt the user to enter the athlete's salary for the year (ensure that the entered value is positive). The user should then enter the name and category of each of the hired professionals. The athlete should be able to hire as many professionals in each category as he/she wants, even if it is more than he/she can afford. Based on the category, calculate the amount that each professional should be paid. After all data has been entered, print the names of each professional hired, how much each is being paid, the total amount the athlete paid, and how much the athlete has left.arrow_forward
- To rt z98.arrow_forwardEntering -1 without any numbers: Requirements: - Enter -1 to terminate enter numbers. You have to enter 3, or more, nonnegative numbers. Enter a number: -1 Good-bye! Entering an invalid number: Requirements: Enter -1 to terminate enter numbers. You have to enter 3, or more, nonnegative numbers. Enter a number: -4 Sorry, invalid number entered. Numbers must be nonnegative values. Enter another number: Entering less than 3 numbers: Requirements: - Enter -1 to terminate enter numbers. - You have to enter 3, or more, nonnegative numbers. Enter a number: 30 Enter another number: 2 Enter another number: -1 Sorry, you didn't enter the required nonnegative numbers for processing. Good-bye! Entering the required numbers: Requirements: - Enter -1 to terminate enter numbers. You have to enter 3, or more, nonnegative numbers. Enter a number: 60 Enter another number: 30 Enter another number: 50 Enter another number: 90 Enter another number: 5 Enter another number: -1 Lowest: 5 Highest: 90 Average:…arrow_forwardThe following lines of code perform the same operation.number = number - 1;number -= 1;number--; Select one: True Falsearrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education