Answer to Question #258003 in C++ for Kelvin Tito

Question #258003

Identify errors in the following code and rewrite.Attach output in screenshot form

#include 

#include void sum()

; // declaring a function

 int a=10

b=20

 c; 

void sum()

 // defining function 

{

 c=a+b;

 cout<<"Sum: "<





1
Expert's answer
2021-10-30T23:54:45-0400

SOLUTION FOR THE ABOVE QUESTION


THE FOLLOWING ARE THE ERRORS IN THE GIVEN CODE


i)The input/output stream is not included i.e. #include <iostream>

ii)The namespace standard is not defined i.e. using namespace std;

iii)The function named sum is defined wrongly with '#include included in the declaration

iv)The variables b and c are not declared

v)The definition of the sum method has no ending curly brackets i.e. "}"

vi)The main method is not included in the program which is executed

vii)No semicolon used at the end of declaration of variable a



CORRECT CODE


#include <iostream>
using namespace std;
//define sum method receiving two parameters and returning the sum
	int sum(int a, int b)
	{
		return a+b;
	}
int main()
{
 	int a=10;
	int b=20;
    //call the sum method
  	int c = sum(a,b); 
   	cout<<"Sum = "<<c<<endl;
  
  }



SAMPLE PROGRAM OUTPUT






Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS