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
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <limits>
#include <cmath>
#include <windows.h>
#include <mmsystem.h>
#include <unistd.h>
usingnamespace 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<streamsize>::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<std::streamsize>::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";
elseif (sum > number == B)
cout << one << " Abundant Number";
elseif (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
@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
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().
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..
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <limits>
#include <windows.h>
usingnamespace 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<streamsize>::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<std::streamsize>::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";
elseif (sum > number)
cout << one << " This is a Abundant Number";
elseif (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.
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <limits>
#define NOMINMAX
usingnamespace 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;
}
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.
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()).
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <limits>
usingnamespace 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<streamsize>::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<streamsize>::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";
elseif (sum > number)
cout << one << " This is a Abundant Number";
elseif (sum < number)
cout << one << " This is a Deficient Number";
return 0;
}
yes, it compiles and does what it was doing before but with less libraries
I dont have to display out
1 2 3 4 5 6
if(sum == number)
cout << one << " This is a Perfect Number";
elseif (sum > number)
cout << one << " This is a Abundant Number";
elseif (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
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.
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!";
}
elseif (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!";
}
elseif (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!";
}
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. :)