Homework help

Hello all, Class started two weeks ago and this is my first time getting my feet wet with coding. Im having an issue with my lab so I was wondering if I could get some help. Im not asking for the code but maybe someone could give me some guidance as to how I should start. Also im not to sure how to use the formula they provided me with. Sorry again, and thanks for the help.

"Design, write and compile, and execute a C++ program that calculates and displays the amount of money, A, available in N years when an initial deposit of X dollars is deposited in a bank account paying an annual interest rate of R percent. Use the relationship that A = X(1.0 + R/100)N. The program should prompt the user to enter appropriate values and use cin statements to accept the data. Use statements such as Enter the amount of the initial deposit in constructing your prompts. Verify the operation of your program by calculating, by hand and with your program, the amount of money available for the following test cases:

Test data set 1: $1000 invested for 10 years at 0% interest
Test data set 2: $1000 invested for 10 years at 6% interest

"

Have you written function main()?
Have you got a pseudo-code?
Not to sure what a pseudo code is, but the lab before this one I was able to make this.

#include <iostream>
using namespace std;

int main ()
{
double x1, x2, y1, y2, midpoint1, midpoint2, slope;

cout << " This program will calculate the slope and midpoint of a line " "\n" "\n" ;

cout << " Input the value of the first point, x1 and y1 " "\n" ;

cin >> x1 >> y1 ;

cout << " Input the value of the second point, x2 and y2 " "\n" ;

cin >> x2 >> y2 ;

slope = (y2-y1) / (x2-x1);

midpoint1 = (x1+x2) / 2 ;
midpoint2 = (y1+y2) / 2 ;

cout << " The slope of the line is " << slope << "," "\n" ;
cout << " The midpoint of the line is ( " << midpoint1 << "," << midpoint2 << " ) " "\n" ;

Now I know this is no where great, but it works. Maybe this will help you gauge where im at.
btw, thanks for a quick reply.
Pseudocode is a cross between human language and a programming language. Although
the computer can’t understand pseudocode, programmers often find it helpful to write an
algorithm in a language that’s “almost” a programming language, but still very similar
to natural language. For example, here is pseudocode that describes your homework
program:

Declare the variables
- A = amount of money
- N = number of years
- X = initial deposit
- R = interest rate
Ask the user for the number of years
Input the number of years
Ask the user for the initial deposit
Input the initial deposit
Ask the user for the interest rate.
Input the interest rate
Compute the amount of money (variable A) by using the formula A = X(1.0 + R/100)^N

Notice the pseudocode contains statements that look more like commands than the
English statements that describe the algorithm. The pseudocode even names variables and describes mathematical operations.

Also im not to sure how to use the formula they provided me with. Sorry again, and thanks for the help.

Use the test data to practice.
For example:
A = 1000(1.0 + 0/100)^10
A = The answer of the formula.
Thank you so much for breaking it down like that !
Sorry to bother you guys again. I provided the line of code I wrote with the error im getting when I start trying to compile the code. I think it has something to do with the a = x(1.0 + r/100) ^n ; statement. I tried googling the errors but still couldn't seem to make sense of it.


int main ()

{
double a, r;
int x, n ;

cout << " This program will calculate the compound interest, to determine the amount of money available. " "\n" "\n" ;

cout << " Enter the amount of the initial deposite " "\n" ;

cin >> x ;

cout << " Enter the amount of the initial interest rate " "\n" ;

cin >> r ;

cout << " Enter the amount of years you want to gain interest " "\n" ;

cin >> n ;

a = x(1.0 + r/100) ^n ;

cout << " The calculated interest is " << a << "\n" ;


return 0;
}

" Error 1 error C2064: term does not evaluate to a function taking 1 arguments

2 IntelliSense: expression preceding parentheses of apparent call must have (pointer-to-) function type

You should use pow to solve something like a = x(1.0 + r/100) ^n ;
For example on how to use the pow(base number,exponential number).
You need to include the cmath library.

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <cmath> //To use the pow (base number,exponential number) function.
using namespace std;

int main() 
{
    cout << "3^2 equals to " << pow(3, 2) << endl;
    cout << "2^3 equals to " << pow(2, 3) << endl;
    cout << "8^0 equals to " << pow(8, 0) << endl;

    return 0;
}



For additional info on the pow operator, look at http://www.cplusplus.com/reference/cmath/pow/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <cmath> //To use the pow (base number,exponential number) function.
#include <iomanip> //To use the fixed and setprecision for formatting.
using namespace std;

int main() 
{
    int X{ 1000 };
    int R{ 0 };
    int N{ 10 };

    cout << "3^2 equals to " << pow(3, 2) << endl;
    cout << "2^3 equals to " << pow(2, 3) << endl;
    cout << "8^0 equals to " << pow(8, 0) << endl;

    double A = pow(X*(1.0 + (R / 100)), N);
    cout << "a = X(1.0 + R/100) ^ n is " << fixed << setprecision(2) << A << endl;

    return 0;
}
Last edited on
Just thought id keep you updated, I got it to work thanks to you ! :D your help is greatly appreciated, you have no idea.
Just thought id keep you updated, I got it to work thanks to you ! :D your help is greatly appreciated, you have no idea.


Who has no idea?

Your help is greatly appreciated


Anyways, if you need help, can you tell us your problem?
Show us your new code that contains the errors.
Topic archived. No new replies allowed.