# Logical errors Example in C/C++ with solution

1. This program contain some logical errors.Find out these error and execute the correct code which shows following output:

#include <iostream>
using namespace std;
void get_input (int num1, int num2, int num3);
int  find_sum  (int& num1, int& num2, int& num3);
void display_output(int& num1, int& num2, int& num3, int& total);
int main()
{
int num1, num2, num3, sum, total;
do
{
get_input (num1, num2, num3);
sum= find_sum(num1, num2, num3);
display_output(num1, num2, num3, total);
cout << "Do you want to continue? (Enter Y/N)"<<endl;
}
return 0;
}
void get_input(int a, int b, int c)
{
cout << "Enter the first number" <<endl;
cin >> a;
cout << "Enter the second number" <<endl;
cin >> b;
cout << "Enter the third number" <<endl;
cin >> c;
}
int find_sum(int& a, int& b, int& c)
{
return a+b+c;
}
void display_output(int& a, int& b, int& c, int& total)
{
cout << "The sum of " << a <<","<< b <<","<< c << " is "
<< total << endl;
}

SOLUTION :

#include <iostream>
using namespace std;
void get_input (int& num1, int& num2, int& num3);
int  find_sum  (int num1, int num2, int num3);
void display_output(int num1, int num2, int num3, int total);
int main()
{
int num1, num2, num3, sum, total;
do
{
get_input (num1, num2, num3);
sum= find_sum(num1, num2, num3);
display_output(num1, num2, num3,sum);
cout << "Do you want to continue? (Enter Y/N)"<<endl;
}
return 0;
}
void get_input(int& a, int& b, int& c)
{
cout << "Enter the first number" <<endl;
cin >> a;
cout << "Enter the second number" <<endl;
cin >> b;
cout << "Enter the third number" <<endl;
cin >> c;
}
int find_sum(int a, int b, int c)
{
return a+b+c;
}
void display_output(int a, int b, int c, int total)
{
cout << "The sum of " << a <<","<< b <<","<< c << " is "
<< total << endl;
} • Title : Logical errors Example in C/C++ with solution
• Posted by :
• Date : 12:11
• Labels :