I need help.
Directions:
Write a program called powersOf2.cpp and save it in your programs directory.
This program should ask the user to input an integer value. It will then raise 2 to all the powers from 0 up to and including the user entered value.
For example, if the user entered 5 the output would be:
2 ^ 0 = 1
2 ^ 1 = 2
2 ^ 2 = 4
2 ^ 3 = 8
2 ^ 4 = 16
2 ^ 5 = 32
For this assignment, you must use a for loop to accomplish this.
Remember to once again:
•Explain the program and its use to the user.
•Check for input that will cause mathematical problems (in this case, to satisfy the conditions of the problem, the entered value must be greater than 0).
•Allow the user to run the program again.
This is the code I have so far:
#include <iostream>
using namespace std;
int main()
{
int x;
int y;
cout << "This program asks for a number then raises 2 to every" << endl;
cout << "number up until the number you put in. The number must" << endl;
cout << "be a whole number from 1 to 20." << endl;
cout << "\n" << endl;
cout << "Please enter your number here: " << endl;
cin >> y;
for (x = 0; x <= 20 ; x^y)
{
cout << x;
cout << " ";
}
cout << endl;
return 0;
}
When I try to run the program it tells me that the third statment in line 22 has no effect (that would be the "x^y" in the for statement). How can I get it to do what the directions say?