NEWBY needs hints

Write your question here.
Ok, so I am new to programming and have spent 6 hours trying to write the formula for POP = 5.5 * e raised to power of (.02(year-2000)).

I keep getting an error even when I try to define "e".

I use the files iomanip and cmath and keyword double with variables pop, and year.


I don't need anyone to do my homework for me, just let me know where I am wrong, or better yet give me a hint on how I can fix it.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  Put the code you need help with here.
#include <iostream>
#include <cmath> 
#include <iomanip>

using namespace std;
    int main()
{
    #define const e = 2.71828182846
    double pop,year;

    cout << "\n Type the year for the population you would like to know: " ;
    cin >> year;

    pop = 5.5 * e * pow(0.02(year-2000);

    cout << "\n The population of the earth in 2020 will be: " << pop << "\n";

    system("PAUSE");
    return 0;
}
You haven't given e a type. It should be a double.
In C++ you should prefer not to use define.

#define const e = 2.718...

will replace occurrences of const with e = 2.718....

const double e = 2.718... or constexpr double e = 2.718 if your compiler supports it.

pow takes two arguments. You're missing a paren on line 15.

Multiplication requires use of the * operator.
if you want e raised to power of something, use the exp() function. That's what it's for.
http://www.cplusplus.com/reference/cmath/exp/
Topic archived. No new replies allowed.