Answer to Question #289664 in C++ for stephanie

Question #289664
  1. How many “bugs” do you see in this C++ code? Give an enumerated list of the errors that you spot in the program, including why you think there is something wrong with it, and how you would fix it.


#include <iostream>

using namespace std

int main(); 

int test1;

int test2;

int test3;

float av;

test1=1;

test2=2;

ave=(test+test2+test3)/2;

cout<<”The average is <<ave; 

return 0;




1
Expert's answer
2022-01-23T10:14:57-0500
/*
#include <iostream>


using namespace std		//Error -1: the statement should be ended with semi-clon (;)


int main(); //Error -2 main function should not be ended with semi-colon 


int test1;	// Error-3: main function should start and end with pair of curly brackets {}


int test2;


int test3;


float av;


test1=1;


test2=2;


ave=(test+test2+test3)/2;	//Error-4: ave is not defined. Rather it is defined as av
							//Error-5: test is not defined. Rather it is defined as test1
cout<<”The average is <<ave; //Error-6: ave is not defined. Rather it is defined as av
								//Error-7: The double quote (") should be in pair.
return 0;
*/
#include <iostream>


using namespace std;
int main()
{
	int test1;	// Error-2: main function should start and end with pair of curly brackets {}
	int test2;
	int test3;
	float av;
	
	test1=1;
	test2=2;
	av=(test1+test2+test3)/2;	
	cout<<"The average is "<<av; 
	return 0;
}

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