Nathaniel10 34 Junior Poster

OK, Narue. Thanks for your reply.

I think I understand the first part of it.

For line 13, the two values should be equal to each other and be 123.
For line 12, the two values should be equal to each other and be the address of variable i.
For line 11, the two values should be equal to each other and be the address of pointer p1.
For line 10, the two values should be equal to each other and be the address of pointer p2.

For the second part, I referred back to my Stroustrup book. It does discusses how the * and & operators do not function identically(?) for chars and ints. It advises the use of reinterpret_cast to deal with conversions of type. I am not at all clear on this, but fortunately, do not need that knowledge in the near future. I will read more on how types affect pointer and de-reference operators.

Nathaniel10 34 Junior Poster

Narue,

Thank you very much for your outstanding explanation of pointers. Like the OP, I am also self-learning C++. Your post has raised my understanding of pointers several levels, as the books and tutorials I read were nowhere near as clear.

I have a follow-up question. (Not to hi-jack the OP's thread, but it is very relevant.) Does nesting/recursion work for the dereferencing operator as well?

int i = 123;
int *p1 = &i;
int **p2 = &p1;
int ***p3 = &p2;
...
int &i = *p1;
int &&i = **p2;
int &&&i = ***p3;

I am suspecting not, as I can't reason through a logical pathway.

Nathaniel10 34 Junior Poster

Your last post is better code than mine, Oliver. In any case, both were better than what the OP has. With yours, 8 lines of code does what the OP used 40 lines to do.

Nathaniel10 34 Junior Poster

@NathanOliver,

I don't see that. There are 4 categories of fees on check so there are 4 cases. I was thinking along the lines of:

double check_fees = 0.0;
char level_checks = ' ';
if (checks < 20) {level_checks = 'a';} 
if (checks => 20 && checks < 40) {level_checks = 'b';} 
if (checks => 40 && checks < 60) {level_checks = 'c';} 

switch (level_checks) {
   case 'a':
      check_fees = 0.10 * checks;
      break;
   case 'b':
      check_fees = 1.90 + 0.08 * (checks - 19);
      break;
   case 'c':
      check_fees = 1.90 + 1.52 + 0.06 * (checks - 39);
      break;
   default:
      check_fees = 1.90 + 1.52 + 1.14 + 0.04 * (checks - 59);
      break;
   }

int low_balance = 0;

if (balance < 400) {low_balance = 1;}
fee = 10.0 + check_fees + 15.0 * low_balance;
cout <<"Bank service charges for the month are $" << fee << " .\n";

Where do you see at least 60 cases?

Nathaniel10 34 Junior Poster

Instead of all the else if statements, I would have used a switch statement.

Nathaniel10 34 Junior Poster

I had a similar problem which I think I posted here. The recommended solution, which worked, was to use a cin.clear() statement to empty the input buffer so cin >> can be used again. Why is cin.ignore the solution for this problem? Does cin.ignore also empty the input buffer?

Nathaniel10 34 Junior Poster

I had to do this very exercise last month. However, the solution looked nothing like what you have.

The values of the set were input into a vector using the push_back() function. Then the stated statistics were found using the sum() function and loops.

However, Vernon is absolutely correct. If you don't understand statistics (mean, variance, etc.), then you can't write a program to compute them. The author of the book I am using has that as the very first rule: You can't program what you don't understand. First, understand the problem.

Nathaniel10 34 Junior Poster

Thinking about this more, I would not have the sums at all.

while ((simple - compound) < 1.00) {
   simple = deposit1 + deposit1 * interest1/100 * years;
   compound = deposit2 * pow(1.00 + interest2/100, years);
   years++;
}
Nathaniel10 34 Junior Poster

I am still just learning C++ so my observations may not be the best. It seems to me that you are using the wrong type for your variables. You are using integers. But when you divide the interest rate by 100 yo get a decimal that is less than one, NOT an integer. You need to change the type to float. In addition, your loop is probably infinite because you will never get an exact equality. The better exit condition is (simple investment - compound investment) < precision amount.

My field is business and I know finance. You are calculating the 'sums' incorrectly. The compound investment is: future balance = (original balance + interest rate) raised to the power of number of years. The simple investment is: future balance = original balance + (original investment * interest rate) * number of years.

N.B. In line 12, you haven't divided interest2 by 100 to make it a rate. As Vidit noted, you are not incrementing by the year.

Nathaniel10 34 Junior Poster

WOW! You guys are pretty patient and generous with this poster who shouts at someone who offers him help rather than thanks that person.