That won't work. Check if it's very near, near or far by using an alternative solution like if (g < x + 20 && g > x - 20) //if its between x + 20 and x - 20 .
You aren't checking if it fulfills one - you need both requirements to be fulfilled to be "very near"!
#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace std;
int main()
{
// use time so numbers are random
srand(time(NULL));
// assign x to a random number out of 100
x = getRand();
...
...
...
return 0;
}
int getRand()
{
return 1+rand() % 100;
}
our teacher is teaching us void main() - and using getch(); to keep the output showing so we can use it later.
WHAT??? Aren't teachers meant to be competent at the subject they teach?
main() must return int. getch() is from an old DOS header (conio.h). It's non-standard, importable, and... old.
WHAT??? Aren't teachers meant to be competent at the subject they teach?
Perhaps in a Utopian world they are. In the real world, there are a great many incompetent people in all professions. Perhaps even moreso with teaching. After all, there is some amount of truth in "Those who can't do, teach.".
Perhaps in a Utopian world they are. In the real world, there are a great many incompetent people in all professions. Perhaps even moreso with teaching. After all, there is some amount of truth in "Those who can't do, teach.".