I made a mistake in the following program

I recently started C++. I am making this program in which I have to input the value of "x" and the program will calculate the value of "y". Whats the mistake

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;
int main ()

{
	int x,y;
	
	cout<<"Please enter the value of x : "<<endl;
	cin>>x;
	
	y=x*x + 2*x + 1;
	
	return 0;
}
closed account (48T7M4Gy)
What did you want the program to do? This will determine the answer to your question. As expected it runs ok.
Last edited on
The program computes the value of y and then exits. You need to print the value before exiting.
when i'll input the value of "x", it should substitute the the value of "x" in that equation(y=x*x + 2*x + 1) and and give me the answer
closed account (48T7M4Gy)
and give me the answer


The answer has been worked out - that's why line 11 was written.

What you need is a new line cout << x;
Last edited on
Topic archived. No new replies allowed.