I made a mistake in the following program

Oct 16, 2015 at 5:43pm
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;
}
Oct 16, 2015 at 5:49pm
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 Oct 16, 2015 at 5:50pm
Oct 16, 2015 at 5:55pm
The program computes the value of y and then exits. You need to print the value before exiting.
Oct 16, 2015 at 5:56pm
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
Oct 16, 2015 at 9:14pm
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 Oct 16, 2015 at 11:22pm
Topic archived. No new replies allowed.