Chilton 22 Junior Poster

@Gonbe: Why'd you give out an answer? This seems like an assignment, so why not let him/her do the work themselves and post it here if they need additional help?

Chilton 22 Junior Poster

In your code there, you're not incrementing count in your for loop. Look your code over a bit.

Chilton 22 Junior Poster

Your array has subscripts ranging from 0 to 3 (4 elements), so when you try to access the array past that point, such as grade[4], it is going to cause you problems.

Chilton 22 Junior Poster

grade[4] is undefined, since the array goes from 0 to 3. If you want to prompt the user to print the first through fourth grades, then keep your loop from 0 to <= 3 but simply print count + 1.

Chilton 22 Junior Poster

You only set mid once, and that was outside of any loop, so it doesn't update when last or first changes.

Chilton 22 Junior Poster

Your asking the user to enter a grade, then testing the array's data before they even enter any information. Once you declare your array, its data is going to be garbage, so that's what you'll be testing against.

Chilton 22 Junior Poster

We are not allowe to use classes yet.

You are using iostream ;)

All joking aside, all your loop does is copy the next value to the position you planned on deleting, but that just makes two copies of the next position's data. The tedious way would be to use two loops. Once you've found the value to delete, start the next loop and copy the next value to the current position.

Also, why is your for loop checking for index < 9? Should it be inv.total?

Chilton 22 Junior Poster

Why not use a list of strings rather than a character array? The list class is made for fast insertion and deletion, without you having to worry about shifting values continually.

Chilton 22 Junior Poster

So in your example a and b are both 10. You add them together and you get 20. Now you want to set a and b to 20 and do it again?

I think it's more on the line of adding the result of a + b to a + b, continually in a loop.

To the OP, you could have a third variable, sum, initialized to zero and do something like:

sum = sum + a + b;

In this case though, a and b wouldn't change.

Question, do you want a and b to change?

Chilton 22 Junior Poster

You have to set c to 0, because it needs to increment until it counts the amount of characters in cols. When it reaches that amount, then you've finished printing one line.

As for c += greeting.size();, c is incremented by the amount of the "greeting" since in the previous statement, cout << greeting;, you've printed out greeting.size() characters.

Chilton 22 Junior Poster

It seems like most of the work is already done. Make some attempt at the code, post it, and we'll give assistance if need be.

Chilton 22 Junior Poster

You could always just test for the student with the longest name, and find the difference in spacing between that name and every other name. In doing so, you can print the correct amount of spaces after each person's name, followed by the list of grades.

Good luck.

P.S. I'm originally from Brooklyn lol

Chilton 22 Junior Poster

InitWord[50] is invalid, in this case, since your array is actually from 0-49. Also, if you want to copy the word to the struct member, you can use strcpy.

Lastly, if you're trying to pass that array to InsertItem, then you'd need to pass a pointer to it and the size. You can also try the string type as well.

Chilton 22 Junior Poster

There is no pAVec member in your class, and neither was one passed to the member function test.

Chilton 22 Junior Poster

What questions do you have about arrays, classes, and stacks?

Chilton 22 Junior Poster

You can extend your range by using unsigned integers, since your numbers aren't going to be negative.

Chilton 22 Junior Poster

It's based on the type of the variable. They each have their limits.

Chilton 22 Junior Poster

If your list is generic, then you wouldn't necessarily need to specify the particular class object would you? What do you have there that is a substitute for the name of a type?

Chilton 22 Junior Poster

It means that the variable direction is default initialized with the character 'A', if you don't pass a character as an argument to the function.

If you do, it replaces that value with the one the caller (you) provided.

Chilton 22 Junior Poster

The point wasn't to do the program for the person asking, though.

Nick Evan commented: True +16
Chilton 22 Junior Poster

Your code tags isn't structured properly.

Also, I'll give a hint. Work it out by hand first. Assume the first population is 755, for instance, and using what you know about the arithmetic operators, find a way to round to 1000. By finding it for this case, you can work out a general formula for any value. In addition, printing an asterisk per 1000 people is easier than rounding to the nearest thousand.

Chilton 22 Junior Poster

In your catch statement, you referred to e but you never used it. Instead of

cout << "exception handled" << endl;

try

cout << e.what() << endl;

That should display the error string that you threw. If you want to specify it as an error, you could use cerr instead of cout as well.

Chilton 22 Junior Poster

Your string and list are empty when you test for their size. Also, you've only opened the file. Where did you read from it?

Chilton 22 Junior Poster

digit_one to digit_four are variables. You don't need to put them in quotes to display them. Review variables and cout structure to get a better handling on these basics.

Chilton 22 Junior Poster

Well, this is obviously taken from a text. What exactly is the purpose of the chapter and/or exercise this excerpt was taken from? I think I should be cautious about how I answer until I know.

To answer your question though, there is a syntax error on the line in question.

cout <<"Encrypted digits:"; << digit_three; digit_four; digit_one; digit_two; << endl;// display encrypted numbers

True, the extraneous semi-colon is a syntax error, but there's more wrong with that line than just that. There are also other syntax errors and intent errors in the line.

True. I noticed the same right after and made some quick changes. Thanks.

Chilton 22 Junior Poster

There's a semi-colon after your string. Remove it.

Also, separate your variables in output by << operators and not semi-colons.

Chilton 22 Junior Poster

What errors did you get?

Chilton 22 Junior Poster

You should pick a better name for your string other than "string", just to be safe. Aside from that, you're indexing your string so each index corresponds to a specific character, in the case of string[7] it'll be 5 and string[8] will be *.

If you want 45, you can test if the next character is an operator. If it isn't, then create a temp and concatenate the previous and the newly tested character to get your number. It's a suggestion.

Chilton 22 Junior Poster

You could use an associative container, such as a map, that has unique key values (in your case integers). The container is self-ordering, so by testing the difference between each successive key value (integer), you can find out which integer you'd need to search for next if their difference isn't 1.

Chilton 22 Junior Poster

In your example, you're neglecting to test if the die rolls on a 6 in your if statement. Also, rather than using

num < 6 && num > 0

, try:

if ((num >= 1) && (num <= 6)) {
// rolls on a correct die value
}

Also, keep in mind that someone could also enter a negative integer as their guess for the die. To be safe, you could declare an unsigned integer variable.

Chilton 22 Junior Poster

My apologies, I may have been in error. If they knew what parkour was, did you only want to print "You have been promoted to cool"?

If that's the case, then:

if(Answer == 'y' || Answer == 'Y')
		cout << "\nYou have been promoted to cool.\n";

is fine. The statements following that were indented as well, so I assumed you wanted to group them together. If you did want to group them, then adding the braces is correct, otherwise you can remove them.

Chilton 22 Junior Poster

Oh, I wasn't doing the work for you, I was just giving you a pointer.

Chilton 22 Junior Poster
bool will_help = true;
char has_question = 'N';
if (will_help == true) {     // added brace here
   cout << "Do you have another question? (Y/N): ";
   cin >> has_question; 
}                            // and here

By adding braces, you're specifying two statements to execute (print and read) if the condition is true.

Chilton 22 Junior Poster

If your if statement has to execute multiple statements, then enclose those in braces.

Chilton 22 Junior Poster

Review the link that was posted before to get a better handling on loops, then try doing your program again.

Chilton 22 Junior Poster

Make an attempt before asking for help, or ask questions about the language details, so you can get a better understanding.

Chilton 22 Junior Poster

Post your updated code, please.

Chilton 22 Junior Poster

Sorry, I think you misunderstood what I meant. In your if and else if statements, make sure that you're using the right form of =. == checks of equality whereas = is assignment.

I didn't mean for you to change mostly every statement with a = to ==.

Chilton 22 Junior Poster

If you're trying to pass the array to the function, you should just pass the name of the array "levelOnePlatform" as the first argument and 50, as the second argument which is its size.

Chilton 22 Junior Poster

There's some syntax problems with your program that you should handle beforehand. In each of your condition statements, make sure you're using == signifying equals rather than = meaning assignment.

Also, cout uses the ostream operator << whereas cin uses the istream operator >>. In addition, it's "cin.get()" rather than "Cin.get()".

Chilton 22 Junior Poster

Thanks everyone for the help.

Chilton 22 Junior Poster

Why the need to mix cout and printf?

Chilton 22 Junior Poster

If you've used "using namespace std;" then putting "using std::cout;" and "using std::cin;" isn't required.

Chilton 22 Junior Poster

Greetings, I've found Accelerated C++ to be a pretty solid foundation in C++, but with regards to the new standard, does anyone know of a good supplemental text that can keep me up to date with said standard?

Any help would be greatly appreciated. Thanks in advance.

Chilton 22 Junior Poster

Work on understanding variables and proper syntax before beginning the assignment. Also, to the poster above, please don't provide answers only suggestions.

Chilton 22 Junior Poster

If you would like to return a newly generated "array" from a function, you can create a pointer to that type and dynamically allocate space for the array, within the grav_force function, set its values, then return its address.

Ex:

double* foo(double, double, int&);

int main(int argc, char* argv[])
{
double* arrPtr(nullptr);
double numOne = 3.14, numTwo = 6.28;
int size = 0;                         // array size variable 

arrPtr = foo(numOne, numTwo, size);   // returns pointer to allocated space on the heap

// Use arrPtr like you would an array but don't forget to free the memory afterwards
delete [] arrPtr;
arrPtr = nullptr;
return 0;
}

// Function accepts two double values to assign to allocated array
// and sets the array size with a reference variable.
double* foo(double firNum, double secNum, int& size)
{
   size = 2;
   double* myNewArrPtr = new double[size];      // allocate space for 2 double values
   myNewArrPtr[0] = firNum;
   myNewArrPtr[1] = secNum;
   // Use myNewArrPtr like you would an array, with size telling you how much 
   // elements you have within.
   // Return pointer to allocated space
   return myNewArrPtr;
}

The example may be a bit silly, but you can return a pointer to a block of memory if you allocate it within the function itself.

Chilton 22 Junior Poster

That code posted was not by the OP. That was simply another EGO post violating our don't do other's homework for them policy.

Ah, thanks for letting me know. I didn't notice that.

Chilton 22 Junior Poster

Is there any other problem with your code now?

Chilton 22 Junior Poster

Why do you have two main functions?

Also, use code tags and check the line the error is identifying.

Chilton 22 Junior Poster

Your node has a data area and a pointer, next, in this case. That pointer just holds the address of the node that follows the current one.

The node at the end of the list, its next pointer would be set to NULL/nullptr, indicating that it is indeed the end of the list.