Question

The program has errors. Identify and make the necessary changes to make the program work. Remember...

The program has errors. Identify and make the necessary changes to make the program work. Remember to follow the rules of functions and arrays. Here is the expected output

Total = 20

Average = 15

Area = 150

Area = 70

Enter a value: 10

Value 1 entered = 10

Enter an integer: 20

Value 2 entered = 20

Enter an integer: 30

Value 3 entered = 30

..................................................................

#include <iostream>

using namespace std;

void total(int, int, int);

double average(int [], int);

void area(int = 30, int); void getValue(int&);

int getValue();

double getValue();

int main() { const int vSize = 5;

int numbers[vSize] = {9, 20, 12, 34, 0};

int num = 18;

double num2 = 1.2;

cout << "\nTotal = " << total(6, 10, 4);

cout << "\nAverage = " << average(numbers, vSize); cout << "\nArea = " << area();

cout << "\nArea = " << area(10, 7);

getValue(num);

cout << "Value 1 entered = " << num;

num = getValue();

cout << "Value 2 entered = " << num;

num2 = getValue(3.14);

cout << "Value 3 entered = " << num2;

return 0; }

int total(int val1, int val2, int val3){ return val1 + val2 + val3;

}

double average(int vList[], int vSize)

{ double average = 0; int sum = 0 for(int i = 0;

i < vSize; i++){ sum = sum + vList[i];

}

average = static_cast(sum) / vSize;

return average;

}

void area(int length = 30, int width){ return length * width;

}

void getValue(int value&){ cout << "Enter a value: ";

cin >> value&;

}

int getValue()

{

int inputVal;

cout << "Enter an integer: ";

cin >> inputVal;

return inputVal;

}

double getValue(){ double inputVal;

cout << "Enter an integer: ";

cin >> inputVal;

return inputVal;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I corrected the errors and got the required output

#include<iostream>

using namespace std;

int total(int, int, int);

double average(int [], int);

int area(int,int = 30);

void getValue(int&);

int getValue();

int main()

{

const int vSize = 5;

int numbers[vSize] = {9, 20, 12, 34, 0};

int num = 18,num2;

cout << "\nTotal = " << total(6, 10, 4);

cout << "\nAverage = " << average(numbers, vSize);

cout << "\nArea = " << area(vSize);

cout << "\nArea = " << area(10, 7);

getValue(num);

cout << "Value 1 entered = " << num;

num = getValue();

cout << "Value 2 entered = " << num;

num2 = getValue();

cout << "Value 3 entered = " << num2;

return 0;

}

int total(int val1, int val2, int val3)

{

return val1 + val2 + val3;

}

double average(int vList[], int vSize)

{

double average = 0;

int sum = 0;

for(int i = 0; i < vSize; i++)

{

sum = sum + vList[i];

}

average = static_cast<double>(sum) / vSize;

return average;

}

int area(int length,int width)

{

return length * width;

}

void getValue(int& value)

{

cout << "Enter a value: ";

cin >> value;

}

int getValue()

{

int inputVal;

cout << "Enter an integer: ";

cin >> inputVal;

return inputVal;

}

Output

Add a comment
Know the answer?
Add Answer to:
The program has errors. Identify and make the necessary changes to make the program work. Remember...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (USING THE PROGRAM MARS) Using the MemoryAccess program we wrote in class as a starting point,...

    (USING THE PROGRAM MARS) Using the MemoryAccess program we wrote in class as a starting point, write a program called LoadStore # Title : Memory access.asm #Desc: Practice initially memory, #in val1 = 0x0a; #int val2 = 0x0b; #int result; #string resultstring = " final answer : "; #string returnchar = "\n"; #void main() { #   result = val1 + val2; #   cout<<< resultstring << returnchar; #} .data val1: .word 0x0a   #store 0xa into variable val1 val2: .word 0x0b   #store...

  • C++ problem where should I do overflow part? in this code do not write a new...

    C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...

  • Fix this C++ code so that the function prototypes come before main. Main needs to be...

    Fix this C++ code so that the function prototypes come before main. Main needs to be declared first. Then call to the functions from inside of main. #include<cstdlib> using namespace std; //prompt user for input void getGrades(int gradeArray[],int size) { for(int i=0; i<size; i++) { cout<<"Enter the grade "<<i+1<<": "; cin>>gradeArray[i]; } } // finding average of all numbers in array float computeAverage(int numbers[],int size) { float sum=0; for(int i=0; i<size; i++) { sum = sum + numbers[i]; //compute sum...

  • 61. The following program is accepted by the compiler:         int sum( int x, int y...

    61. The following program is accepted by the compiler:         int sum( int x, int y )         {             int result;             result = x + y;            }                            T__   F__ 62. The following implementation is accepted by the compiler:         void product()         {             int a; int b; int c; int result;             cout << "Enter three integers: ";             cin >> a >> b >> c;             result = a * b * c;            ...

  • Hello everyone! I am working on my assignment for C++ and I'm having a bit of...

    Hello everyone! I am working on my assignment for C++ and I'm having a bit of trouble on the value producing functions, I am creating a program wherein I have to input a value and I need to create a function called square value where in it will square the value I have input. I cannot seem to figure out this part. Here is the code that I have so far, and thank you for any help. I greatly appreciate...

  • Change your C++ average temperatures program to: In a non range-based loop Prompt the user for...

    Change your C++ average temperatures program to: In a non range-based loop Prompt the user for 5 temperatures. Store them in an array called temperatures. Use a Range-Based loop to find the average. Print the average to the console using two decimals of precision. Do not use any magic numbers. #include<iostream> using namespace std; void averageTemperature() // function definition starts here {    float avg; // variable declaration    int num,sum=0,count=0; /* 'count' is the int accumulator for number of...

  • Having to repost this as the last answer wasn't functional. Please help In the following program...

    Having to repost this as the last answer wasn't functional. Please help In the following program written in C++, I am having an issue that I cannot get the reducdedForm function in the Rational.cpp file to work. I cant figure out how to get this to work correctly, so the program will take what a user enters for fractions, and does the appropriate arithmetic to the two fractions and simplifies the answer. Rational.h class Rational { private: int num; int...

  • Hello, I have written a code that I now need to make changes so that arrays...

    Hello, I have written a code that I now need to make changes so that arrays are transferred to the functions as pointer variable. Below is my code I already have. #include<iostream> #include<string> #include<iomanip> using namespace std; //functions prototypes void getData(string id[], int correct[], int NUM_STUDENT); void calculate(int correct[], int incorrect[], int score[], int NUM_STUDENT); double average(int score[], int NUM_STUDENT); void Display(string id[], int correct[], int incorrect[], int score[], double average, int NUM_STUDENT); int findHigh(string id[], int score[], int NUM_STUDENT);...

  • 1. Please provide a C++ program which faithfully reads a list of non-negative integer scores, ultimately...

    1. Please provide a C++ program which faithfully reads a list of non-negative integer scores, ultimately terminating the list reading when the sentinel value (lets use -9999) is entered. The program should then correctly report the number of non-negative scores entered and the arithmetic mean (average) of those scores 2. Demonstrate your programs behavior in response to errors on input (that is, show that it faithfully rejects improper input such as alphabetic characters, decimal points, and commas). Here are some...

  • What are the errors in the following code? My professor gave us this prewritten code and...

    What are the errors in the following code? My professor gave us this prewritten code and asked us to find the errors in it so that it can run properly #include <cstdlib> #include <ctime> #include <iostream> using namespace std; // input: integer // output: none // adds five to the given parameter void addFive( int x ) { x += 5; } // input: none // output: a random number int generateRandomNumber() { srand( time(0) ); return rand() % 100;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT