Hello,
I do not claim to be an expert on C++.
scanf(%d%d,&x,&y) means it is looking for decimal integer. So, %d%d means "here come 2 decimal integers, and they are called variables x and y" The & symbol is the address operator of the variable. C is more cryptic than C++, but I think you will like it better than FORTRAN.
I think you can write the code:
// Let's declare and initialize the values
int x = 0, y = 0;
// User interaction to gather X and Y
// Put me in a loop though for error checking
cout << "Enter coordinates for your X: ";
cin >> x >> y;
If I were you, I would put these in loops to ensure error checking... what happens if someone tried to enter in -3, 7? Your code would probably fail.
Enjoy.
Christian
kc0arf
Posting Virtuoso
1,937 posts since Mar 2004
Reputation Points: 121
Solved Threads: 57
Hi,
I like your answer asqueella. Thank you for the hint there. As she is just beginning C++, she might not know what the code means. I'd break it down for her to help her understand where you are going with it.
// This declares the integers. Don't need to initialize them to
// zero, because we fill them right away, and no decisions are made on them.
int x,y;
cout << "Enter coordinates for your X: ";
// note that since you are missing a \n, there will be no "return"
// while (true) means "loop forever unless we break out of it"
while (true)
{
cin >> x;
// check to see if (X is greater or equal to 3) OR "||" (X is less than 0)
// this is the error check code. The lines || mean OR
cout << endl .......
// the else "break" command means if you get here, break out of the while loop
}
Hope that helps you out with the comments on the code. I also hope I didn't insult you by telling things you already knew.
Christian
kc0arf
Posting Virtuoso
1,937 posts since Mar 2004
Reputation Points: 121
Solved Threads: 57
agreed, it is always a good habit to get into. the only time u will see good programmers avoiding the practice is when writing kernel code - when every instruction counts, and then it is ur responsibility to be absolutely positive to double check that every variable is not used before given a value.
infamous
Junior Poster in Training
77 posts since Mar 2004
Reputation Points: 47
Solved Threads: 2
cybergirl << could u at least tell us WHY it isn't running?? can u compile it? does it fault when it runs? where does it fault?? some INFO
infamous
Junior Poster in Training
77 posts since Mar 2004
Reputation Points: 47
Solved Threads: 2