This is what I have so far but how do I set the value of my integer to 2401 and make an integer counter that will count to 110 but I also have to have this in the body of the loop?
++(*ptr); cout<<*ptr<<" is stored at " <<ptr<<endl;
#include <iostream>
usingnamespace std;
int main()
{
int i = 0;
int newint = 1, thatpoint = 2;
int *ip = &newint;
cout << "Value of *ip: " << *ip <<endl;
cout << "Address of newint pointing : " << hex << ip << endl;
ip = &thatpoint;
cout << "After pointing to newint" <<endl;
cout << "Value of *ip: " << *ip <<endl;
cout << "Address of thatpoint pointing: " << hex << ip <<endl;
cout << "You have now received two Pointer Addresses"<<endl;
*ip = 2401;
for(i = 0; i < 110; i++) {
++(*ptr); //The mandatory body of the loop
cout<<*ptr<<" is stored at " <<ptr<<endl; //The mandatory body
}
return 0;
}
My professor gave us the ptr body for the loop but didn`t tell us too intialize it so im going to assume it means pointer. I`m trying to write a loop with an integer counter that counts to 110. In his words he said "in the body of the loop does this: ++(*ptr); cout<<*ptr<<"is stored at " <<ptr<<endl;".
#include <iostream>
usingnamespace std;
int main()
{
int newint{1};
int thatpoint {2};
int *ptr = &newint;
cout << "Value of *ptr: " << *ptr <<endl;
cout << "Address of newint is :" <<ptr << endl;
cout<<endl;
ptr = &thatpoint;
cout << "After pointing to thatpoint" <<endl;
cout << "Value of *ptr: " << *ptr <<endl;
cout << "Address of thatpoint pointing: " << ptr <<endl;
cout << "You have now received two Pointer Addresses"<<endl;
*ptr =0;
for(int i = 0; i < 110; i++) {
++(*ptr); //The mandatory body of the loop
cout<<*ptr<<" is stored at " <<ptr<<endl; //The mandatory body
}
return 0;
}
also, when you set cout<<hex it will stay that way unless you change it back to cout <<dec.
You can copy and paste this below to see what I mean rand() is a random number.
#include <iostream>
usingnamespace std;
int main()
{
int num =rand();
int num2 = rand();
cout<<"num is: "<<num<<endl;
cout<<"num2 is: "<<num2<<endl;
cout<<"cout<< hex<< num :"<< hex<< num <<endl;
cout<<"cout is still in hex. Here is cout<<num2 :"<< num2 <<endl;
cout<<" Change cout back to dec. Here is cout<< dec << num2 : "<< dec << num2 <<endl;
}
Also, I removed hex because it works on my machine. I don't know about yours. If you need it just remember to switch bac to decimal "dec" when needed.