questions about point?

P

P1u70

#include <iostream>
using namespace std;
int main()
{
int a,b;
int *point_1,*point_2,*temp_point;
cin >> &a >> &b << endl; // any wrong here?
point_1=&a;
point_2=&b;
if ( a<b )
{
temp_point=point_1;
point_1=point_2;
point_2=temp_point;
}
cout << *point_1 << *point_2 << endl;
}
 
M

mlimber

P1u70 said:
#include <iostream>
using namespace std;
int main()
{
int a,b;
int *point_1,*point_2,*temp_point;

Don't declare variables until you can initialize and use them, and then
put them in the minimum scope possible.
cin >> &a >> &b << endl; // any wrong here?

Yes and this won't compile. You can't change the address of automatic
variables, and you can't output to an input stream. You could change
the values of a and b like this:

cin >> a >> b;
point_1=&a;
point_2=&b;
if ( a<b )
{
temp_point=point_1;
point_1=point_2;
point_2=temp_point;

There's also std::swap().
}
cout << *point_1 << *point_2 << endl;
}

Cheers! --M
 
C

carcrashnights

P1u70,

You were right in where the mistake is. That line should read:

cin >> a >> b;

You won't send std::endl to std::cin, but you would send that to
std::cout, like you do later in the program. You also should be parsing
integers, not pointers to integers (although, this might be a change
for you from C to C++).

-carcrashnights
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top