Question

Find the five problems with this program. Do not change the functionality or rewrite the program....

Find the five problems with this program. Do not change the functionality or rewrite the program.

#include <iostream>

void multiply(int x = 1, int y);

int main()
{
int length, width, area;

cout << "Enter length and width of a rectangle ";
cin >> length, width;

area = multiply(length, width);

cout << "The area is " << area << endl;

area2 = multiply(width);

cout << "The second area is " << area2 << endl;

return 0;
}

void multiply(int x= 1, int y);
{
return x * y;
}

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

#include <iostream>

1) //here using namespace std; is required for cin,cout

void multiply(int x = 1, int y); 2) // return type should be integer

int main()
{
int length, width, area;

cout << "Enter length and width of a rectangle ";
cin >> length, width; 3) //here for taking input yoou should write like cin>>length>>width;

area = multiply(length, width); //the function type is void but here expecting return value.

cout << "The area is " << area << endl;

area2 = multiply(width); 4) //area2 variable is not declared and one more parameter required for function call

cout << "The second area is " << area2 << endl;

return 0;
}

void multiply(int x= 1, int y); 5) //remove semicolon from here to run whole function body
return x * y;
}

///////////////////////error free code////////////////////////

#include <iostream>
using namespace std;
int multiply(int x,int y);
int main()
{
int length, width, area,area2;
cout << "Enter length and width of a rectangle ";
cin >> length>>width;
area = multiply(length, width);
cout << "The area is " << area << endl;
area2 = multiply(length,width);
cout << "The second area is " << area2 << endl;
return 0;
}

int multiply(int x, int y)
{
return x * y;
}

Add a comment
Know the answer?
Add Answer to:
Find the five problems with this program. Do not change the functionality or rewrite the program....
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
  • Find the errors in the following program. You must use pass by reference. #include <iostream> using...

    Find the errors in the following program. You must use pass by reference. #include <iostream> using namespace std; void area2(int area, int length, int width = 0); int main() { int length, width, area; // for rectangle use two arguments cout << "Enter length and width of a rectangle" << endl; cin >> length >> width; cout << "The area is " << area2(area, length, width) << endl; // for squares use one argument cout << "Enter side of a...

  • Find two syntax errors in the following program: #include <iostream> using namespace std; int area(int length,...

    Find two syntax errors in the following program: #include <iostream> using namespace std; int area(int length, int width = 0); int main() { int length, width; // for rectangle use both arguments cout << "Enter length and width of a rectangle" << endl; cin >> length >> width; cout << "The area is " << area(length, width) << endl; // for square, only need first argument cout << "Enter side of a square" << endl; cin >> length; cout <<...

  • 1:Fix the problems with this class definition, do not change program functionality #include <iostream> using namespace...

    1:Fix the problems with this class definition, do not change program functionality #include <iostream> using namespace std; class Rainbow{   private:   static int numRainbows;   string colors;   public:   Rainbow() { colors = "Red Orange Yellow Green Blue Violet"; numRainbows++; }   Rainbow(string colors) ; colors(colors) { numRainbows++; }      void setColors(string colors) { this->colors = colors; }   string getColors() { return colors; }   int getCount() { return numRainbows; }      bool operator==(const Rainbow & lhs, const Rainbow& rhs)   {   return lhs.colors == rhs.colors;...

  • C++ program. int main() {    Rectangle box;     // Define an instance of the Rectangle class...

    C++ program. int main() {    Rectangle box;     // Define an instance of the Rectangle class    double rectWidth; // Local variable for width    double rectLength; // Local variable for length    string rectColor;    // Get the rectangle's width and length from the user.    cout << "This program will calculate the area of a\n";    cout << "rectangle. What is the width? ";    cin >> rectWidth;    cout << "What is the length? ";    cin >>...

  • Hello I have a question. I would like to check if the code follows this requirement....

    Hello I have a question. I would like to check if the code follows this requirement. Rectangle.h - A complete Rectangle Class including both declaration and definition appRectangle,cpp separate in two different files the class definition and implementation Code: rectangle.h // Rectangle class declaration. class Rectangle { private: double width; double length; public: void setWidth(double); void setLength(double); double getWidth() const; double getLength() const; double getArea() const; }; //************************************************** // setWidth assigns a value to the width member. * //************************************************** void...

  • C++ Type in the above program . Before running the program, change each of the question...

    C++ Type in the above program . Before running the program, change each of the question marks to the numbers 1 through 5 indicating the order in which that line will be executed. Run the program and check your numbers. Fix and rerun if necessary. Submit the program and the output. #include <iostream> using namespace std; //prototypes void DemonstrateProc1(); void DemonstrateProc2(int num); int main() { cout << "?. Execution starts with main. " << endl; DemonstrateProc1();       cout << "?....

  • The statement in the following program is in the incorrect order. Rearrange the statements so that...

    The statement in the following program is in the incorrect order. Rearrange the statements so that they prompt the user to input the shape type (rectangle, circle, or cylinder) and the appropriate dimension of the shape. The program then outputs the following information about the shape: For a rectangle, it outputs the area and perimeter, for a circle, it outputs the area and circumference; and for a cylinder, it output the volume and surface area. After rearranging the statements, your...

  • 81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5...

    81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5 );                    int BoxVolume(int length = {1}, int width = {1}, int height = {1});                                                     T__   F__                                                                     82. The following function is implemented to swap in memory the          argument-values passed to it:         void swap(int a, int b)                   {           int temp;             temp = a;             a = b;             b = temp;        ...

  • Program a clean_string function that combines both the convert_lower and remove_punct functionality in one function. In...

    Program a clean_string function that combines both the convert_lower and remove_punct functionality in one function. In other words, take a string as a parameter and return a clean version of the string that has no punctuation, no spaces and is all lower case. #include <iostream> #include <string> using namespace std; // TODO: Add your clean_string function here int main() { string line;    getline(cin, line); while(line != "quit") {    cout << clean_string(line) << ": " << line << endl;...

  • SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1...

    SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1 #include<iostream> using namespace std; // add function that add two numbers void add(){    int num1,num2;    cout << "Enter two numbers "<< endl;    cout << "First :";    cin >> num1;    cout << "Second :";    cin >>num2;    int result=num1+num2;    cout << "The sum of " << num1 << " and "<< num2 <<" is = "<< result;   ...

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