Im making a game

Pages: 12
let me just say that this is for a project so please dont outright hand me an answer.
right now the code is not a game its still a work in progress, I recently added some code and now it will not compile on my computer. any help would be amazing, Thanks

 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 #include #include #include #include #include #include #include #include using namespace std; int main() { cout << " Hello, " << endl; cout << " I am going to show you a number between 1-100. " << endl; cout << " I would like you to tell me if it is a Perfect, Abundant, or Deficient. " << endl; cout << " Press Enter to Continue " << endl; cin.ignore(numeric_limits::max(),'\n'); srand(time(0));//Starts random number generator int number = rand() % 99 + 1;//Using Modulus operator to isolate values 1-5+1 cout << number; cin.ignore( std::numeric_limits::max(), '\n' ); cout << " Is this number a Perfect, Abundant, or Deficient ? " << endl; cout << " Press A if you think it's a PERFECT NUMBER" << endl; cout << " Press B if you think it's a ABUNDANT NUMBER" << endl; cout << " Press C if you think it's a DEFICIENT NUMBER" << endl; Sleep (2500); int rand,one = 1, sum = 0, A, B, C, X; while (one < number) if (X == A == B == C) cin << X << endl; { if(number % one == 0) sum = sum + one; one++; } if(sum == number == A) cout << one << " Perfect Number"; else if (sum > number == B) cout << one << " Abundant Number"; else if (sum < number == C) cout << one << " Deficient Number"; return 0; }
Line 34:
cin has arrows this way. cin >>
To output a new line, you have to use cout. cout << endl (and better is cout << "\n").

That is one heck of a lot of libraries to include, is it really necessary?! You don't seem to use anything from <cmath> <mmsystem.h> <unistd.h> for example.
im just using every library that i have learned from the proffessor, it is possible i dont need some, i need <unistd.h> for the Sleep tho, and i need <cmath> pretty sure anyways... i could be wrong

i changed the << to >> on 34. still wont compile. error message sudgestion parenthesies , sorry im terrible at spelling
Last edited on
If you must use Sleep(...) from <windows.h> AND you want to use std::numeric_limits<std::streamsize>::max() then you need to include it like this:
 12 #define NOMINMAX #include
otherwise you'll get conflicting definitions.

I think this encompasses what you need for your code:
 1234567 #include #include #include #include #define NOMINMAX #include
Last edited on
@booradley60, i am not saying your wrong, infact im sure your right , but i dont recall being taught #define NOMINMAX from the prof so i dont think i should use that.

it was compiling untill i added the ABCX integers, and the cin >> X
Did you also change this on line 34?
 To output a new line, you have to use cout. cout << endl (and better is cout << "\n").

iamlearning wrote:
i am not saying your wrong, infact im sure your right , but i dont recall being taught #define NOMINMAX from the prof so i dont think i should use that.

I suggest removing windows.h altogether, then. That means removing the Sleep(...) function call on line 30, but I don't think that's a problem.

It's either that, or you remove std::numeric_limits<std::streamsize>::max().
Last edited on
thanks everyone for the tips , ill keep working on it and come back to this thread if i have issues
ok folks im back, ive taken out libraries that wasnt needed , and ive taken out broken code so it is compiling again.
if i take out cin.ignore(numeric_limits<streamsize>::max(),'\n'); then it just displays everything all at once , and i dont like that.
I want this program to ask me if the number it displays is perfect/abundant/deficient so earlier i had given it the A,B,C,X inergers , tried to give A,B,C a value for perfect, abundant, deficient and made X ==A==B==C. which didnt work obv...
my code looks like this now..

 1234567891011121314151617181920212223242526272829303132333435363738394041424344 #include #include #include #include #include using namespace std; int main() { cout << " Hello, " << endl; cout << " I am going to show you a number between 1-100. " << endl; cout << " I would like you to tell me if it is a Perfect, Abundant, or Deficient. " << endl; cout << " Press Enter to Continue " << endl; cin.ignore(numeric_limits::max(),'\n'); srand(time(0));//Starts random number generator int number = rand() % 99 + 1;//Using Modulus operator to isolate values 99+1 cout << number; cin.ignore( std::numeric_limits::max(), '\n' ); cout << " Is this number a Perfect, Abundant, or Deficient ? " << endl; cout << " Press A if you think it's a PERFECT NUMBER" << endl; cout << " Press B if you think it's a ABUNDANT NUMBER" << endl; cout << " Press C if you think it's a DEFICIENT NUMBER" << endl; Sleep (2500); int rand,one = 1, sum = 0; while (one < number) { if(number % one == 0) sum = sum + one; one++; } if(sum == number) cout << one << " This is a Perfect Number"; else if (sum > number) cout << one << " This is a Abundant Number"; else if (sum < number) cout << one << " This is a Deficient Number"; return 0; }

i am not sure hot to proceed further , where i took it earlier was a disaster !
I assume the problem is that it won't compile? You have three options:
1. Use #define NOMINMAX as suggested above.
2. Remove lines 5 and 27 as suggested above.
3. Replace numeric_limits<streamsize>::max() on lines 15 and 21 as suggested above. You could say something like cin.ignore(100, '\n') instead, but your code is vulnerable to someone putting in more than 100 characters at your prompt.

EDIT: typo!
Last edited on
what is written right now , will compile.

im going to do the suggested changes. and try that too , see whats different

edit, after making the sudgested changes code does not compile...

 1234567891011121314151617181920212223242526272829303132333435363738394041424344 #include #include #include #include #define NOMINMAX using namespace std; int main() { cout << " Hello, " << endl; cout << " I am going to show you a number between 1-100. " << endl; cout << " I would like you to tell me if it is a Perfect, Abundant, or Deficient. " << endl; cout << " Press Enter to Continue " << endl; cin.ignore(100, 'n\') srand(time(0));//Starts random number generator int number = rand() % 99 + 1;//Using Modulus operator to isolate values 99+1 cout << number; cin.ignore(100, 'n\') cout << " Is this number a Perfect, Abundant, or Deficient ? " << endl; cout << " Press A if you think it's a PERFECT NUMBER" << endl; cout << " Press B if you think it's a ABUNDANT NUMBER" << endl; cout << " Press C if you think it's a DEFICIENT NUMBER" << endl; int rand,one = 1, sum = 0; while (one < number) { if(number % one == 0) sum = sum + one; one++; } if(sum == number) cout << one << " This is a Perfect Number"; else if (sum > number) cout << one << " This is a Abundant Number"; else if (sum < number) cout << one << " This is a Deficient Number"; return 0; }
Last edited on
anyone have any other tips for me ?
I was careless. cin.ignore(100, 'n\') is wrong. It should be cin.ignore(100, '\n') I meant to put \n instead of n\. I've changed my earlier response to reflect this. By the way, you only needed to do one of those options, not all three. #define NOMINMAX is not needed if you're not including windows.h anymore.
Last edited on
i just did really fast and basic pseudocode here ...

generate random number from 1 to 100
ask user if number generated is perfect, abundant, deficient
keep track of results
repeat 10x
give a percentage grade of how many correct

THAAAT is what im trying to do. the more and more i work on it though the further away i feel i am going
Ok, start here and see if it does what you want to do. We can worry about repeating 10x later. I've taken your code and modified it juuuuust a little bit so that it will compile. Basically, I fixed the cin.ignore lines so that they compile properly. I put streamsize::max() stuff back in there since <windows.h> has been removed (thus, no conflict on the name max()).
 123456789101112131415161718192021222324252627282930313233343536373839404142 #include #include #include #include using namespace std; int main() { cout << " Hello, " << endl; cout << " I am going to show you a number between 1-100. " << endl; cout << " I would like you to tell me if it is a Perfect, Abundant, or Deficient. " << endl; cout << " Press Enter to Continue " << endl; cin.ignore(numeric_limits::max(), '\n'); srand(time(0));//Starts random number generator int number = rand() % 99 + 1;//Using Modulus operator to isolate values 99+1 cout << number; cin.ignore(numeric_limits::max(), '\n'); cout << " Is this number a Perfect, Abundant, or Deficient ? " << endl; cout << " Press A if you think it's a PERFECT NUMBER" << endl; cout << " Press B if you think it's a ABUNDANT NUMBER" << endl; cout << " Press C if you think it's a DEFICIENT NUMBER" << endl; int rand,one = 1, sum = 0; while (one < number) { if(number % one == 0) sum = sum + one; one++; } if(sum == number) cout << one << " This is a Perfect Number"; else if (sum > number) cout << one << " This is a Abundant Number"; else if (sum < number) cout << one << " This is a Deficient Number"; return 0; }
Last edited on
yes, it compiles and does what it was doing before but with less libraries

I dont have to display out
 123456 if(sum == number) cout << one << " This is a Perfect Number"; else if (sum > number) cout << one << " This is a Abundant Number"; else if (sum < number) cout << one << " This is a Deficient Number";

but i wanted to start with having it generate a random number and then telling me if it was perfect/abundant/deficient which i had and have now. but that is not what the final draft if you will , would be doing
Last edited on
So right now the code tells you which type of number it is. Now we want to see if the user made the correct guess. So the first step is go get the user's input. The next step is to see if they're right. This isn't the whole program, I just cut out some of it to show the important part with changes.
 12345678910111213141516171819202122232425262728293031323334 cout << " Is this number a Perfect, Abundant, or Deficient ? " << endl; cout << " Press A if you think it's a PERFECT NUMBER" << endl; cout << " Press B if you think it's a ABUNDANT NUMBER" << endl; cout << " Press C if you think it's a DEFICIENT NUMBER" << endl; char userGuess; //NEW cin >> userGuess; //NEW int rand,one = 1, sum = 0; while (one < number) { if(number % one == 0) sum = sum + one; one++; } if(sum == number && userGuess == 'A') //added another condition! { //commented out: cout << one << " This is a Perfect Number"; cout << "You are correct! This is a Perfect Number!"; } else if (sum > number && userGuess == 'B') //added another condition! { //commented out: cout << one << " This is a Abundant Number"; cout << "You are correct! This is an Abundant Number!"; } else if (sum < number && userGuess == 'C') //added another condition! { //commented out: cout << one << " This is a Deficient Number"; cout << "You are correct! This is a Deficient Number!"; } else { cout << "Sorry, you are incorrect!"; }
Last edited on
nvm, lol that was a dumb question.....
i have added what you wrote and its working amazing .... my god!!!
Last edited on
another question for you boo, do you do this for a living ? because i need to interview someone for a communications class. 7 questions ... take about 10-15 minutes...
You can PM me, or just post your questions in your thread in the Lounge: http://www.cplusplus.com/forum/lounge/114783/ I'm sure lots of people would be willing to help if the questions aren't too intrusive. :)
Pages: 12