Hello, I am new to C++ programming. I need to do this problem for a class but I'm a bit stuck, it's giving me many errors, could anyone point out what the problem is please?

This is the problem: A country club, which currently charges $2,500 per year for membership, has announced it will increase its membership fee by 4% each year for the next six years. Write a program that uses a loop to display the projected rates for the next six years.

And this is what I have so far:

#include<iostream>
using namespace::std;

int main()
{
int counter, total, fee;
counter = 1;

while (counter <= 6) {

	cout>> "Enter initial payment: ";
		cin>>total;
		fee = 4/100*total;
		total = total + fee;
		counter = counter + 1;
}
cout << "The total per year is: " << total << endl;
 
return 0;
}

Move these lines to before the while statement:

cout>> "Enter initial payment: ";
cin>>total;

Move this line into the while statement (before the counter increment):

cout << "The total per year is: " << total << endl;

I'd also change that line to indicate what year it is reporting on.

Also you are using int to hold your values, and 4/100 when it is an integer equals 0. Use float.
There are other things you could improve, but that should fix your problem.

Edited 5 Years Ago by Momerath: n/a

Good for you for finding the CODE button. Thanks. However, your posting is still a little short of good:
Please provide the actual "many errors" (or really, just the first couple is enough)
In addition:
May I suggest that you look up operator += rather than using e.g. total = total + fee;
Although the declaration int counter, total, fee; is legal, it is a mistake waiting to happen. Better to declare each variable on its own line.

One thing to understand is that the compiler is [B]trying[/B] to give you good information when it tells you something is wrong. If you read it carefully, and [B]think hard[/B] about what the compiler authors are trying to tell you, it is not just possible but likely that you will be able to understand the problem in your code. There are two tricks:
Once the compiler has seen the first error, it is confused; so you need to pay attention only to the first one or two errors
If a syntax error is reported, the problem is as likely [B]before[/B] the reported line as on it. For instance a missing semi-colon or closing parenthesis above may lead to a syntax error here

Edited 3 Years Ago by happygeek: fixed formatting

Thank you very much for the responses, I have changed what was advised. However I'm still getting 25 errors, these are the 2 first lines:

1>h:\users\javi\documents\visual studio 2008\projects\cecs 2200\cecs 2200\mfee.cpp(11) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'

1> h:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1021) : see declaration of 'std::operator >>'

Okay, I found out that I had written "cout>>" and it was giving me many errors. Now the only problem I'm having is that is not adding up the 4% to the total.

Change fee to be of type double (it will fit in a float, but live large, j/k). You'll need to change total also, otherwise whatever you add to it will be truncated.

Like Momerath said, the division of two integers will be an integer, so 4/100 = 0 (and 101/100 is 1, since there is no decimal). Change 4 to 4.0 or cast it to a double.

Edited 5 Years Ago by jonsca: n/a

The problem may be that you are doing integer division, which may not have the result you expect. (Try printing the result of 4/100. Then multiply that by anything...) solution is to do the division 'in your head' and just use the constant .04

Thank you very much guys, it's working. I appreciate it :)

This question has already been answered. Start a new discussion instead.