I have an assignment to "Create a C++ program that creates a decimal pointer, creates a variable set to a decimal value, then assigns the address of the variable to the pointer." I was kind of confused as to what I needed to do here, but this is what I came up with. The output I get from this code seems kind of awkward. I'm just hoping I'm understanding this problem correctly, and that what I created is sufficient. Any advice would be appreciated..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
usingnamespace std;
int main()
{
double count = 5.1;
double *pCount = &count;
cout << "The Value of the count is " << count << endl;
cout << "The address of count is " << &count << endl;
cout << "The address of pCount is " << &pCount << endl;
system("Pause");
return 0;
}
Perhaps you did more than was asked for. If the instructions are followed meticulously , you end up with something like this:
1 2 3 4 5 6 7 8 9
int main()
{
// "Create a C++ program that
double *pCount; // creates a decimal pointer,
double count = 5.1; // creates a variable set to a decimal value,
pCount = &count; // then assigns the address of the variable to the pointer."
return 0;
}
Of course there is no output. But unless there is more to the assignment than stated, no output is required.
I'll post the output I got that I found a little awkward..
The Value of the count is 5.1
The address of count is 0019FA28
The address of pCount 0019FA1C
Press any key to continue...
Press any key to continue...
I guess I was mostly confused as to why the program asks you to 'press any key to continue' twice..
@Chervil- I will consider your simplified code. An output may be required. I'll have to look into that..
I guess I was mostly confused as to why the program asks you to 'press any key to continue' twice..
Your program does that just once. However, if you are running the program from within an IDE (a combined editing/compiling/execution environment) then the IDE may itself be adding its own separate "Press any key to continue" after your program has ended.