C++ Program to square a number

I need to write a program that reads in an integer and writes the square of the entered value.
*Get the input with a function called getNumber()
* Display the result with a function called showAnswer(int answer)
* Put the getNumber and showAnswer functions in a file called inOut.cpp


My code is resulting in errors. It worked when I used x instead of getNumber and y instead of showAnswer. What am I doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;
int main ()
{
int getNumber();
int showAnswer(int answer);

cout << "Enter number";
cin >> getNumber();

showAnswer(int answer) = getNumber() * getNumber();

cout << "The square of " << getNumber() << " = " << showAnswer(int answer) << endl;

return 0;
}
Last edited on
* You have stated what you should do.
* You have shown some pieces of code that are neither a proper program nor matches your task's requirements.
* You don't ask any apparent question.

How do you expect us to react to that?
I've changed my input to ask a specific question and to show my new code that has the errors.
well if your just squaring it u can just do it times its self.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

using namespace std;

int main ()
{
        int x;//number you want to square

       cout << "Enter the number you want to square: ";
       cin >> x;
     
       x = x * x;

      cout << x << endl;

      return 0;
}
Topic archived. No new replies allowed.