Chilton 22 Junior Poster

One thing to note is that accumulate's third parameter, 0 in this case, makes your result an integer because the function takes that type as its value. Therefore, the fractional part of your code would be disregarded.

Change the 0 to 0.0.

Chilton 22 Junior Poster

True enough. I assumed wrongly that it had more to do with setting a specific size of an array, with regards to allocation and things like that. Also, since the program isn't really asking for the set of data but only the largest and smallest out of those entered, it doesn't make sense.

Chilton 22 Junior Poster

Use a vector.

Chilton 22 Junior Poster

Following what mike said,

// And then, in main(), you will need to dereference the pointer before using <<.
int main() {
  //...
  cout << *(checking[0]) << endl; //remember that C++ indices start from 0, not 1.
  cout << *(checking[1]) << endl;
  cout << *(checking[2]) << endl;
  //..
};

, you would need to call your getbalance function from *(checking[0]), since it gives you the first object, *(checking[1]) giving you the second object, and so on. Also, you can make your get functions const, since they don't change the state of your object.

Chilton 22 Junior Poster

DayOfTheWeek is your class type; you're trying to make it a string variable name as well.

Use a different name for the string.

Also,

void DayOfTheWeek::setDay(string DayOfTheWeek)
{
	day = DayOfTheWeek;
}

DayOfTheWeek needs to be changed, and your get function doesn't store the returned value anywhere.

Chilton 22 Junior Poster

You've posted your main twice, instead of account.h.

Chilton 22 Junior Poster

Did you press enter after you ran your code?

Chilton 22 Junior Poster

Shouldn't it be:

(*it)->ItemID
Chilton 22 Junior Poster

I stand corrected then.

Chilton 22 Junior Poster

Shouldn't you only need to explicitly initialize them when the value isn't going to be one?

Chilton 22 Junior Poster

The this pointer is used to refer to the current object being utilized. For instance, if you have an overloaded assignment operator for a class, and you'd like to test whether or not an object is being assigned to itself, that operator is used to check.

Based on your code, intVal, the i should be uppercase if that is your constructor. Aside from that, the purpose of valCount is to count how many objects you create of type IntVal. Static variables are allocated once and exist for the entirety of your program, and retains its value after being used.

Also, static variables are initialized to 0, for basic types, by default.

Chilton 22 Junior Poster

You'll have to look through. Start from main. Make sure you close it properly, then continue until each function is separate.

Chilton 22 Junior Poster

You are trying to define your functions in a function. Check your braces on each one.

Chilton 22 Junior Poster

Wasn't the assignment telling you not to use if, or while statements?

Also, it asks for you to do this in a function. Following the suggestion given, you can save many lines of code and create a similar function to return the largest value of the three.

Chilton 22 Junior Poster

If you know the amount of bytes the type has, and the amount of bits in a byte, unless it's unsigned, the range for int, for example is:

0 to (2^(b * 8) /2)-1 for positive values and
-1 to -((2^(b * 8)) /2) for negative values where b is the number of bytes of the type and 8 is the number of bits in a byte.

You divide by 2 because there's two sets of ranges here, positive and negative and raise it to the second power because we're working in binary which only has two values: 0, 1.

In the case of unsigned int, the values range from:

0 to (2^(b * 8)) - 1

Chilton 22 Junior Poster

When you declare a variable, array, etc, you don't want to try and initialize it afterwards. Keep in mind that there's a difference between declaring a variable and initializing a variable.

To make a long story short, if you declare a variable in a function or file, for instance, don't try to declare it again.

Look over your code to find the faults. If not that, then when you try and compile it, it should indicate where the issue is.

Chilton 22 Junior Poster

No problem.

In your main function, the nested for loops aren't needed because you are initializing the array with the values.
Ex:

int numbers[3][4] = { {8, 16, 9, 52}, { 3, 15, 27, 6 }, { 14, 25, 2, 10} };

If you wanted to enter the values yourself, you could do something like:

for (int a = 0; i < 3; a++) 
   for (int b = 0; b < 4; b++) 
      cin >> numbers[a][b];

But, in doing this, you would just have to declare your array without any initialization list.

Chilton 22 Junior Poster

Hello.

If you've initializing a two dimensional array, then group your numbers as such. In this case, you have three sets of four integers i.e.

int numbers[3][4] = { {8, 16, 9, 52}, { 3, 15, 27, 6 }, { 14, 25, 2, 10} };

Along with this, you don't need to put

int numbers[][]

each time you need to use the array. It was already declared at the start of main, so remove every other line that declares an array after the first time.

Also, if you're initializing the array, then the loop in main is useless. All you'd need to do is call findMax and it should return the result. Hope it helps.

Chilton 22 Junior Poster

In your if statement, shouldn't those be assignment statements rather than checking equality?

Also, temp is an array pointer, so trying to assign another address to it (if that's what you were trying to do) would cause a problem. If you just wanted to copy the string into temp, use strcpy. The thing is, if you did it that way, you'd have 3 calls to strcpy.

You could always use the string class for the student's name, and save yourself the headache.

Chilton 22 Junior Poster

Along with what L7 mentioned, in your while loop leftName and rightName isn't updated and neither are your i or length variables.

Also, you'd never actually begin the loop, since you're testing 0 != 0. If you are doing an anagram, are you just trying to scramble the characters in the string or do you want it to be a meaningful word?

Chilton 22 Junior Poster

You've hit the nail on the head. You'd want structure in your programs, especially if it's a big one.

In addition, separating the files keeps functions that are related confined to one area. Keep it simple.

Chilton 22 Junior Poster

In the instructions function and in the welcome function, you're calling game() without any arguments, when the function is stated to take 5.

Chilton 22 Junior Poster

Using static_cast isn't really an advanced way. I mean, if you want the simplest then following the advice to simply assign it to an integer variable should suffice.

You can always add a comment explaining what it does, just to make your intentions clear.

Chilton 22 Junior Poster

I apologize if I wasn't explicit enough in telling you that.

Chilton 22 Junior Poster

I should've said declaration/prototype.

In the definition of Spr_Blit, you've specified the default. Remove it from there and put it in the prototype instead.

Also, it looks like you're passing functions as arguments to another function. There's a particular type of syntax that's involved in doing that.

int foo (int r) {
return r * r;
}

int main()
{
int (*pfoo)(int); // ptr to a function that accepts an int and returns an int
pfoo = foo;      // pfoo now points to the function foo
return 0;
}
Chilton 22 Junior Poster

Your default argument should be in the function's declaration.

Chilton 22 Junior Poster

That's the problem. When day is 30, your cout statement increments it to 31, from where you try to read in the stock price for stock[31] which gives you a problem.
Rather than using ++day, use day + 1, since it doesn't increment day.

Also, if you're using floating point variables, initialize them as such. Good luck.

Edit: If you're looking for a sort and efficiency isn't what's important (as of now), then try bubble or insertion sort.

Chilton 22 Junior Poster

What moschops was referring to was creating a variable of type string, rather than one of type char[]. That way, you'd be able to read in any name and test whether or not it's equal to "Jeanne" using the compare function.

Along with this, if you're initializing name to "Jeanne", then you shouldn't have the user try to change name. Lastly, you're testing name being equal to name, which is always going to be true. This doesn't actually compare the strings, themselves, but the address where they're located.

Chilton 22 Junior Poster
string str;

getline(cin, str, '\n'); // '\n' is the delimiter
Chilton 22 Junior Poster

In your reverse function, even though you're passing r1, it isn't changed. You're only making changes to r2, which is local to your reverse function.

Chilton 22 Junior Poster

Oh, I'm actually saying you should check it to that. You've specified that MAX_ACCOUNTS is the amount you'd like the user to have, but elsewhere you've used a constant value i.e. 10 rather than the variable MAX_ACCOUNTS.

Your counter variable should be comparing itself to the amount you specified when you declared your array of objects. Still, you'd have a problem if the user exits before each object is given values. If you're specifying the amount of objects you'd want the user to utilize, then you could always remove the input test and have them read in data for MAX_ACCOUNTS amount of objects.

I apologize if I'm a bit wordy with this.

Chilton 22 Junior Poster

Even if you set MAX_ACCOUNTS to be 5, your do while loop still checks that counter is less than the integer 10 rather than MAX_ACCOUNTS, assuming that 1 is continually entered after counter surpasses MAX_ACCOUNTS.

You'd be pretty much trying to use an object that you never created, is what I think the problem is.

Chilton 22 Junior Poster

It's fine. I'm learning, too, so I'll try to answer what I can.

Is the size 5000 mandatory, or are you just looking for a way to create a smaller array that isn't predefined?

You can always specify the size when you allocate.

Check this out.

I know you'd rather not check out code, but since it wasn't covered in class, getting an understanding of it is fine. Here's hoping it helps out.

Chilton 22 Junior Poster

I'm not sure if this is what you're leading towards, but you can always allocate memory during execution with malloc and a given size.

Chilton 22 Junior Poster

Check how many times you're updating sum4 per each iteration.

Chilton 22 Junior Poster

As caut mentioned, you can't read in with a comma. In addition, you could always make the class variables private and use a member function to set them rather than allowing main() direct access to them.

Chilton 22 Junior Poster

guess is declared to have a size of 50, but ranges from 0 - 49, right? You're trying to read into guess[50] which should be outside of the range.

Another thing, why declare a size of 50 if you're only apparently using one string to hold the guess? Keep in mind that string holds 50 individual strings and not a string of length 49.

Chilton 22 Junior Poster

You're counting how many times the function is called recursively, correct?

If that's the case, then you'd need a counter. Still, it wouldn't just be any counter though. You'd need one that retains its value even after it's used again.

This looks like C++, so think of a what is available for you that allows a variable to retain its value when called again or just in general. Here's hoping you come to your desired solution.

"givemetehcodez" isn't going to happen. Good luck.

Chilton 22 Junior Poster

Also, for future reference, the = sign signifies assignment. Later on, if you're comparing, for instance, numeric values then a double equals sign == is used to check for equality.

But, as the poster above me mentioned, used strcmp to compare strings.

Chilton 22 Junior Poster

I believe j should be assigned the value of i, seeing that after the completion of the inner loop, one value would be sorted, hence not needing to start the search from subscript 0 again.

Chilton 22 Junior Poster

Do you want to know what source code is, or do you want someone do to your assignment?

Chilton 22 Junior Poster

Your program is using the array subscript to serve as a node which is the problem. Even though you removed the data, the second subscript, pq[1], isn't going to change.

Have you tried doing it with a linked list?

Chilton 22 Junior Poster

In C, arrays start with 0. In your case, you'll always be adding some data out of the preallocated boundary you've set when declaring your array. Also, your code is confusing the way it's structured there. Use the code tags to situate your work better.

Here's hoping it helps.

Chilton 22 Junior Poster

It should actually be "<= k" rather than less than.

Use 9 as an example and you'll see. The for loop ends and fails to mod 9 against 3, hence returning a value of 1.

Chilton 22 Junior Poster

Your code is in the wrong section though. Maybe asking if it can be moved to the Java section would garner better help.

Chilton 22 Junior Poster

And here I thought the point wasn't to simply give the answer.

Aia commented: Yes, it is. +6
Chilton 22 Junior Poster

I'd settle for for $5000.00. Pick me :P

Chilton 22 Junior Poster

You can try seeding the random number generator with a call to time().

Chilton 22 Junior Poster

Rather than asking others to do the assignment, a little bit of research would go a long way.

Read and understand.

Chilton 22 Junior Poster

Well, you can start off with the first two: 2, and 3, and store them in an array. From there, think of the conditions for a number to be prime and implement it, keeping in mind to compare each successive value against the prime array.

Here's hoping it helps.