So what is the problem you are having? If you want to generate all numbers less than n that equall 2^k-1 than you can do this
for(int k = 0; k < (int)pow((double)2,k) - 1; k++
{
// check if (int)pow((double)2,k) - 1 is prime
}
So what is the problem you are having? If you want to generate all numbers less than n that equall 2^k-1 than you can do this
for(int k = 0; k < (int)pow((double)2,k) - 1; k++
{
// check if (int)pow((double)2,k) - 1 is prime
}
First things first. when you want to check if more than one thing is equall to the same value you have to do
if(x <= 100 && y <= 100 && z <= 100)
Secondly you can only fave one return value in a function. You can not return three things like you are doing.
When you say the outside numbers you mean the numbers that are going to be multiplied together like a standard multiplication table?
In your system you could have a CR/LF for \n. This would mean you have two charecters to get rid of. An easy way to get arroung this is to take in everything as a string and then convert the string to get what you need. If you want to use ignore than I would suggest using cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n')
. You do need the <limits>
header to use this. What this says is to eat everything in the stream up to the maximum size of the stream untill you hit a \n, then consume the \n.
You need to define the size of the 2d array. The way you have it now it should the compiler will make it 2X12 whn you actually need it to be 12X12. I would change it to int prodouct[ROW_SIZE][COLUMN_SIZE];
We are not going to do your homework for you. If you have some code that you would like us to check post it. If all you are going to do is beg for code than you should realize that you are violating the member’s rules.
You know you can write a simple program to find that out. You could also look at the link umesh314 posted and you should be able to figure it out. You can even do what I did and go to Google. Looks like the first link explains it pretty well.
The problem looks like you are causing memory corruption. This coefficients1 = new int[deg1+1];
need to come after cin >> deg1;
in your readpoly function. This is also the case with your second function. Right now you are initalizing your array with a number from a variable that has not been initalized yet. If you get the size from the user first then declare the array you should be okay. you also need to change line 55 to Polynomial * a = new Polynomial;
. Just an FYI both functions do exactly the same thing so you dont really need both functions.
Your constructor should look like this
Polynomial::Polynomial()
{
degree = 0;
coeffs = NULL;
}
currently you are doing nothing with the vector you have in your function. since it is a local variable of the function it gets created and destrroyed everytime you call the function. If you want to get all of the words from a text file into a vector you can do that in main by simply doing:
string word;
vector<string> fileWords;
ifstream fin("word.txt");
while (file >> word)
{
fileWords.push_back(word);
}
Ill give you a hint. You will need to use 2 for loops.
What part are you getting hung up on? Do you know how to create a struct?
Static functions are generally used when you have static data members in a class and you want to be able to acess the static data. You have to have a satic function to acess static data since it is seperate from the objects of that class.
What exactly is the error you are getting? Do you know where it is coming from? Posting 1400 lines of code with no indentation, no comments and poorly used variables names will not help you. You need to be specific with what you want. I doubt someone is going to go through 1400 lines of unformatted code for you.
@ jainny - If you are having a problem start a new thread and post what you issue is. compile time error is not enough information. You have to show your code and also what the error is.
You can put a space after the asterix
Maybe you should put the check for j being greater than zero first. You might be trying to access a negative index. Have you printed out j to check what the value is?
well one thing i can see is that you never reset the file stream to the begining when you go from your first while loop to your second while loop. You really need to indent your code better. As is it is very hard to follow. Here is an example of some better indentation.
int main()
{
int foo = 1;
int bar = 2;
if(foo == bar)
{
// do something
}
else
{
if (bar - 1 == foo)
{
// do some more
}
else
{
// do something else
}
}
cin.get();
return 0;
}
do you want the class to be templated or just the functions of the class?
Have you steped through your code to see what the values are? You could also put in cout
statements to print out the values in the function to see if the data is correct.
for line 121 you have double shirt_price=0, uniform_cost=0;if(feet <= 6)
. What is the if doing at the end of the line? This will have an impact on all of your other if statements.
You can pass a string to a function that needs a char *
by using the c_str()
method of the string class. the c_str()
function returns a const char *
that holds what the string contains. in order for this to work the function you are passing the string into needs to except a const char *
instead of a normal char *
.
Sorry my mistake. You should be using && not || in your if statement. The three numbers will form a triangle only if all three inequalities are true. If any of them are false then they will not make a triangle.
Welcome to the world of dealing with floating point numbers. My suspiscion is that 1 + 2 as a double is giving you something like 3.0000000000001 which will be greater than 3. If you have a debugger where you can step through your code I would do that to see what the values are.
You havent even posted a full program requierment and the code to show what you have done. What do you expect us to do?
How do you think this should be done when using a class instead of seperate function?
line 11 should be
void printout(ifstream& infile, ofstream& outfile ,string names[numRows],double results[numRows][numCol],double average[numRows]);
Are you asking about something like this?
if(something)
{
if(somethingelse)
{
//...
}
else
{
//...
)
}
else
{
if(somethingelse)
{
//...
}
else
{
//...
}
}
Depending on what you can use I would use a map to store the posistion and the charecter that needs to be deleted. then you can use the map to delete the unwanted values and to restore them as well. I have implemeted a verxion of this that does work for the case you gave but I havent fully tested it. This should help you to see how everything is flowing. If you have a good debugger I would suggest stepping through the code to see what it is doing.
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
string name = "Mike W. Heintzman";
string deleters = "mie";
map <int, char> erased;
cout << deleters << endl;
cout << name << endl;
// find all of the leters needed to be deleted and get the pos
for(size_t i = 0; i < name.size(); i++)
{
for(size_t j = 0; j < deleters.size(); j++)
{
if(tolower(name[i]) == deleters[j])
erased.insert(pair<int, char>(i, name[i]));
}
}
// remopve the leters. this will need to be done in revers order to preserve indexes
map<int, char>::reverse_iterator rit = erased.rbegin();
map<int, char>::reverse_iterator rend = erased.rend();
while(rit != rend)
{
name.erase(rit->first, 1);
++rit;
}
cout << name << endl;
// put leters back
map<int, char>::iterator it = erased.begin();
map<int, char>::iterator end = erased.end();
while(it != end)
{
name.insert(it->first, 1, it->second);
++it;
}
cout << name;
cin.get();
return 0;
}
What is the code you have now?
If you fell posting a solution that is too advanced for them to turn in then I'm fine with that. I'd just hate to see something I wrote getting turned in and people asking me why I gave someone a complete program for a homework problem.
What is N?
The problem is he wasnt wasnt able to easily get there himself thats why he asked. The person either didnt want to do it or didn't know how so by you giving them the answer it does them nothing but get them further behind in their lessons.
Have you tried splitting the equation up to see if you are getting the values you expected?
Are you getting the wrong answer? Are you getting any compiler errors? Have you tried splitting the equation up to see if you are getting the values you expected?
It is called a copy constructor because it takes a reference to an object of its own type and creats a new object that is a copy of the object passed into the constructor. take this as an example
std::string foo("foobar"); //uses single argument constructor
std::string bar(foo); // uses the copy constructor to copy the contents of foo into the new object called bar.
! Is the factorial symbol. a factorial is defined as n! = 1 * 2 * 3 * ... * n-1 * n
. Also 0! = 1. You will ned to write a function that will calculate that. If you know how to use a for loop it is pretty simple to do.
All you need to do is use rand to get a random number in the range of your array and then use that number for the index of your array. Something like this:
cout << arr[(rand() % sizeOfArray)];
if (something == token)
cout << "You have a token. It is: " << token;
Bump a 3 year old thread and put code on it that wont work unless the compiler was made befor 1998? The code you posted wont even work for all casses. What if the order is string 3, string 2 and string 1? No where do you print that combination.
The code I posted will run on a standard conforming complier but turbo c++ is not standard. We do not do your homework for you. You come up with the code and we will help you fix it.
Not to be rude AD but I'll do it for $4,000 USD. A guy has to make money :)
What code do you have?
Well you can use the string type. The string type can hold pretty much every character that is on the standard us keyboard.
#include <string>
#include <iostream>
using namespace std;
int main()
{
string username, password;
cout << "Please enter a username: ";
cin >> username;
cout << "Please enter a password: ":
cin >> password;
cin.ignore(80, '\n'); // clear input buffer
cout << "Username: " << username << endl;
cout << "Password: " << password << endl;
cin.get(); // pause program
return 0;
}
What do you mean by having a username made of numbers? Do you want a text username that gets encrypted into numbers?
You need a carry variable to store the addition of *Num1 + *Num2
. then you need to add carry % 10
to sum. After that you need to dived carry by 10 to get what needs to be carried over to the next addition. You shout get something like this.
int carry = 0;
// in loop
carry = carry + *Num1 + *Num2;
*sum = carry % 10;
carry /= 10;
// in loop
switch statements use an int type so if you are storing the value you are getting from the user in a char variable than you need to use a char for your cases. 1
is not the same as '1'
. Your code should look like this.
switch(input)
{
case '1': //...
break;
case '2': //...
break;
//...
}
Well I know you want someone here to teach you but I dont see the point if there are perfectly good lessons somewhere else. http://www.cplusplus.com/faq/sequences/strings/split/ has a very good tutorial on how to accomplish what you need. I would suggest try using what is there and see what you come up with. If youy still need help post the code you have, any errors you are getting and/or what it should be doing and what it is not doing and you should get some help.
Well you can read in each line from the file and see if you find a match
Just get rid of the paramater in the function so it looks like this void draw();
and then change the function like this
void Creatures::draw()
{
al_convert_mask_to_alpha(sprite, al_map_rgb(255,0,255));
al_draw_bitmap(sprite, getX(), getY(), 0);
}
This will let you use the sprite variable of the class.