-3

There is an error in this line

cin >> X >> Y;

This is the function it belongs into

void InputData(int *X,int *Y)
{
    cout << "Enter 2 integer values: ";
    cin >> X >> Y;
}

Below is the whole code

#include <iostream>
using namespace std;
void Message();
void InputData(int *X, int *Y);
void OutputData(int X, int Y, int Sum);
int ComputeSUM(int X, int Y);

int main()
{
 int X1,X2,SUM;

    Message();
    InputData(&X1,&X2);
    SUM=ComputeSUM(X1,X2);
    OutputData(X1,X2,SUM);
    return 0;
}
void Message()
{
    cout << "This program computes and displays SUM of 2 integer values!" << endl <<endl;
}

void InputData(int *X,int *Y)
{
    cout << "Enter 2 integer values: ";
    cin >> X >> Y;
}

void OutputData(int X, int Y, int Sum)
{
    cout << "The SUM of " << X << " and " << Y << " is " << Sum << endl;
}


int ComputeSUM(int X, int Y)
{
    int Sum;
    Sum=X+Y;                 //return(X+Y)
    return(Sum);
}

See what's on the terminal

See what's on the terminal

------------------------------------------------------------ Below is the original code in C language

#include <stdio.h>
#include <conio.h>
void Message();
void InputData(int *X, int *Y);
void OutputData(int X, int Y, int Sum);
int ComputeSUM(int X, int Y);

int main()
{
 int X1,X2,SUM;

 clrscr();

 Message();
 InputData(&X1,&X2);
 SUM=ComputeSUM(X1,X2);
 OutputData(X1,X2,SUM);
 getch();
 return(0);
}
void Message()
{
  printf("This program computes and displays SUM of 2 integer values!\n\n");
}

void InputData(int *X,int *Y)
{
 printf("Enter 2 integer values; ");
 scanf("%d%d",X,Y);
}

void OutputData(int X, int Y, int Sum)
{
  printf("The SUM of %d and %d is %d\n",X,Y,Sum);
}


int ComputeSUM(int X, int Y)
{
  int Sum;

  Sum=X+Y;                 //return(X+Y)

  return(Sum);
}
  • 3
    C++ isn't C, C++ doesn't work like C, and in many places you can't do things the same way in C++ and C. And attempting straight and direct translation between languages (written, spoken, or programming) is almost never going to turn out well. Instead reimplement the algorithms, or the design, or perhaps even do a new design that fits the target language better. And if you're serious about learning C++, please invest in [some good C++ books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282) and take classes. – Some programmer dude Jan 26 '22 at 12:55
  • For your specific problem and how to solve it, do some research about *references* in C++, and how to pass function arguments by reference. – Some programmer dude Jan 26 '22 at 12:57
  • Just side note, try to write more c++ rather than c(c++ = c, c with classes ,STL ,templates). you can create a class which does this in more c++ way - This will be a good practice – kobi Jan 26 '22 at 13:04

2 Answers2

1

Change this:

void InputData(int *X,int *Y)

To this:

void InputData(int &X,int &Y)

And this:

InputData(&X1,&X2)

To this:

InputData(X1,X2)

And read about 'Passing By Pointer Vs Passing By Reference' for better understanding.

-2

cin >> X >> Y; ->cin >> *X >> *Y;

  • 1
    Please invest a little bit more time when answering and 1) format your answer appropriately, 2) explain what your code does, what the problem is and how your solution helps. – BDL Jan 26 '22 at 13:31