help still confused

Apr 27, 2013 at 2:11am
been at this last 3 days.. algorithm im stuck on ...
newAmount = FutureValue(amount,interestRate)
// output "The new dollar amount is ", newAmount
// Stop
//
//
//
// num FutureValue(num initialAmount, num interestRate)
// Declarations
// num finalAmount
// finalAmount = (1 + interestRate/100) * initialAmount
// return finalAmount

Ive read the tutorials perhaps im not comprehending how these things look completed i began to write this like this its wrong but based on the example im looking at in my book and online it matches the example unless this is for a different type of function i dont like functions im finding out..

int newAmount = int FutureValue(amount*interestRate);

its supposed to be for the part
newAmount = FutureValue(amount,interestRate)
Apr 27, 2013 at 2:23am
You need a function called FutureValue(int amount, int interestRate).

1
2
3
4
5
6
7
int FutureValue(int amount, int interestRate)
{
int Value = 0;


return Value;
};


Apr 27, 2013 at 2:25am
oh is that the same on most of these or just the 2 future value parts or is it used to find final amount as well?
Apr 27, 2013 at 2:30am
compiler flags this int Value = 0;
Apr 27, 2013 at 2:32am
oh got it was a ; blasted things i hate them lol
Apr 27, 2013 at 2:32am
I don't know if its the same, but just going by what you want.

The compiler flags it because its not used in your code. Its just been initialized.
Apr 27, 2013 at 2:39am
// Declarations
// num amount
// num newAmount
// num interestRate
// output "Please enter the dollar amount. "
// input amount
// output "Please enter the interest rate(e.g., nine percet should be entered as 9.0). "
// input interestRate
// newAmount = FutureValue(amount,interestRate)
// output "The new dollar amount is ", newAmount
// Stop
//
//
//
// num FutureValue(num initialAmount, num interestRate)
// Declarations
// num finalAmount
// finalAmount = (1 + interestRate/100) * initialAmount
// return finalAmount

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
   int amount, newAmount, interestRate;
   
   cout <<"Please enter the dollar amount."<<endl;

cin>> amount; 
             
    cout <<"Please enter the interest rate(e.g., nine percet should be entered as 9.0). "<<endl;

cin>> interestRate; 
 
 int FutureValue(int amount, int interestRate);

int Value = 0;


return Value;

int FutureValue(int initialAmount, int interestRate);
int finalAmount 
finalAmount =(1+ int interestRate/100)*initialAmount;

return finalAmount;
 
};


Thats what i got what am i doing wrong if you dont mind helping me figure out whats going wrong with it says last functions no good but program stops half way too i don't know what im doing wrong ;/
Apr 27, 2013 at 2:54am
Functions are their own things. Because of this, they need to be opened and closed with brackets.

1
2
3
4
5
6
7
int FutureValue(int initialAmount, int interestRate)  //this is a function
{ //<----open brace
int finalAmount 
finalAmount =(1+ interestRate/100)*initialAmount;  //type is already declared.

return finalAmount;
}// <---close brace 


They also have to be placed outside of any other functions and before anything that uses them:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int FutureValue(int initialAmount, int interestRate)  //this is a function
{ //<----open brace
int finalAmount 
finalAmount =(1+ interestRate/100)*initialAmount;  //type is already declared in function header

return finalAmount;
}// <---close brace

int main(int argc, char *argv[])
{
   int amount, newAmount, interestRate;
   
   cout <<"Please enter the dollar amount."<<endl;

cin>> amount; 


You already have a function for FutureValue, you don't need to include the one I gave you.
Last edited on Apr 27, 2013 at 2:56am
Apr 27, 2013 at 3:02am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using namespace std;

int FutureValue(int initialAmount, int interestRate);
{
int finalAmount; 
finalAmount =(1+ int inteestRate/100)*initiarlAmount;

return finalAmount;
}
int main(int argc, char *argv[])
{
   int amount, newAmount, interestRate;
   
   cout <<"Please enter the dollar amount."<<endl;

cin>> amount; 
             
    cout <<"Please enter the interest rate(e.g., nine percet should be entered as 9.0). "<<endl;

cin>> interestRate; 

system("PAUSE");[code]
[/code]

still says 3 errors i had it go to 1 on the first time now 3 so they go before the main int makes sence cause it reads top down instructions right whats wrong with it do you see it?
Apr 27, 2013 at 3:08am
on line 6 you are declaring an int called inteestRate as a right hand value (rvalue). This is not good syntax. I think you intended to use interestRate here.

On the same line you multiply the result by intiarlAmount, which i think is supposed to be initialAmount.

on line 3 you have a semicolon at the end of the line. You don't need that there.

Be careful on line 20, although its okay to do input float data into an integer, you will lose some decimal places.
Last edited on Apr 27, 2013 at 3:09am
Topic archived. No new replies allowed.