I need help in my C++ class.

I am in currently enrolled in a C++ course and haven't taken coding in 5 years. My professor glazes over topic and just assign this question:

Please write and run a C++ code to implement the following task: The variable x starts with the value 0. The variable y starts with the value 5. Add 1 to x. Add 1 to y. Add x and y, and store the result in y. Display the value in y on the screen.

Here is what I have so far,

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
int x = 0;
int y = 5;
int answer = x + 1;
int answer2 = y + 1;

return 0;
}


The part that I am stuck on is Add x and y, and store the result in y. How do I store in y?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

int main()
{
    int x = 0 ; // The variable x starts with the value 0.
    int y = 5 ; // The variable y starts with the value 5.

    x = x + 1 ; // Add 1 to x.
    y = y + 1 ; // Add 1 to y.

    y = x + y ; // Add x and y, and store the result in y.

    std::cout << y << '\n' ; // Display the value in y on the screen.
}
Topic archived. No new replies allowed.