why am i getting a massive number

Well title says it all, everytime i execute this program i get a MASSIVE number (like 4.95066e-324) , i dont know where im going wrong. please take a look at my code and pseudocode that was provided for me.

// Start
// 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 beentered 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
32
#include <iostream>
#include <string>

using namespace std;


int main() {
	
	double amount;
	double interestrate;
	double newamount;
	
	
	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;
	double futurevalue(double initialamount, double interestrate);
	cout << "The new dollar amount is " << newamount;
	
	return 0;
}

double futurevalue(double initialamount, double interestrate) {
	
double finalamount;
finalamount = (1 + interestrate/100) * initialamount;

return finalamount;
}

4.95066e-324 is not a massive number. It means 4.95066 × 10-324. That's very close to zero.

The problem is that newamount is not initialized.
Last edited on
oh my goodness im dumb haha, how would i go about doing that? declaring it ? or just switching it out for finalamount? my instructor wrote the psuedocode and it just doesnt seem right.
Look at the comments of your original post
// newAmount = FutureValue(amount,interestRate)


You need to actually call your futurevalue function from main.
http://www.cplusplus.com/doc/tutorial/functions/
L18 is a function declaration (prototype). These are usually placed after any #includes not in the middle of code. I suspect you mean to call the function here as per the appropriate comment.

We can look at you code and ask: where are 'newamount'? Only on lines 11 and 19:
1
2
double newamount;
cout << "The new dollar amount is " << newamount;

The first is a declaration, but it does include initializer. Here are examples of initialization:
1
2
3
double newamount {};  // sets value to 0.0
double newamount {3.14};  // sets value to 3.14
double newamount = FutureValue(amount,interestRate); // sets value to whatever the FutureValue returns 

Your second line reads the current value of 'newamount'. Alas, the value was never set.
but it does include initializer
???
According to https://en.cppreference.com/w/cpp/language/declarations
int answer {42} ; is a declaration

int is decl-specifier-seq

answer {42} is init-declarator

answer is declarator

{42} is initializer that performs direct initialization. The initializer is optional.

Last edited on
@keskiverto - I took your words to mean that double newamount; is a declaration and also an initializer which, of course, isn't right as there's no initializer. I see now that you meant that initializer was optional. Sorry :)
Topic archived. No new replies allowed.