In: Electrical Engineering
Analyze following program and Find Syntax errors.
#include<iostream>
int show(int x)
int main()
{ int A,B;
char B=10;
cout<<”Enter Value of A”;
cin<<A;
show(A)
show(50)
}
cin.get();
}
int show(int x);
{
cout<<”Value is =” <<X
cout<<endl;
}
Analysis of Given Code :
#include<iostream> //including iostream header. iostream includes necessary information for program.
int show(int x) //declaring function of integer data type "show" by passing parameter x of integer data type
int main() //declaring main function. program execution is begins here.
{ //Entering into the main function.
int A,B; //Declaring two variables A,B of integer data type.
char B=10; //Declaring character data type variable B and assigning value 10 to B.
cout<<"Enter Value of A";//Printing "Enter Value of A".
cin<<A; //Taking input
show(A) //calling function show() by passing A value.
show(50) // calling function show() by passing value 50.
} //main function ends;
cin.get(); //reads input character
}
int show(int x); //defining function show().
{ //Entering into show function.
cout<<"Value is =" <<X //Printing value of X.
cout<<endl; //printing new line.
} //show() function ends.
Correct Code :
#include <iostream> //including iostream header. iostream includes necessary information for program.
using namespace std; //compiler uses std namespace
int show(int x); //declaring function of integer data type "show" by passing parameter x of integer data type
int main() //declaring main function. program execution is
begins here.
{ //Entering into the main function.
int A,B; //Declaring two variables A,B of integer data type.
//char B=10; //it's an error because we are already declared
variable B as integer data type.
cout<<endl; //printing new line.
cout<<" Enter Value of A"; //Printing "Enter Value of A".
//cin<<A; //it's an error because for cin we should use
>>operator.
cin>>A; //Taking input from keyboard
show(A); //calling function show() by passing A value.
show(50); // calling function show() by passing value 50.
}
int show(int x) //defining function show().
{ //Entering into show function.
cout<<" Value is =" <<X //Printing value of X.
cout<<endl; //printing new line.
} //show() function ends.
Output :