what am i doing wrong here?

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* 
Write a program that finds the amount in a savings account after a certain time has gone by. 

Task 1 Ask the user for the original amount of money, the interest rate and the time.

Task 2 Calculate the amount of money you will have if the original amount of money, P, is earning interest at 
     r% for t years (compounded annually), the amount of money, A, will be: 
       A = P(1 + r/100)t 

Task 3 The output should look like this: 
     After ____ years at interest rate ____%, $____ will become $_______.
*/

#include <cstdlib>
#include <iostream>
#include <cmath>


double  getPrincipal();
double  getRate();
double  getYears();
double computeAmount(double principal, double rate, double years);
void displayAmount(double principal, double rate, double years, double amount);





using namespace std;

int main(int argc, char *argv[])
{
    
    getPrincipal();
    getRate();
    getYears();
    computeAmount();
    displayAmount();
   
      
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

double  getPrincipal()
{
        double principal;
        cout << "what is the principal ammount?" << endl;
        cin >> principal;
        return principal;
   
}

double  getRate()
{
        double rate;
        cout << "What is the percentage rate?" << endl;
        cin >> rate;
        return rate;
        }


double  getYears()
{
        double years;
        cout << "Over how many years will the money stay in the bank?" << endl;
        cin >> years;
        return years;       
        }




//function that computes the amount based on the principal, rate and years
double computeAmount(double principal, double rate, double years)
{
       double computeAmount;
       computeAmount = principal pow((1 + rate / 100),years);
       cout << computeAmount << endl;
       return computeAmount;
}


//function that displays the principal, rate , years, and amount


void displayAmount(double principal, double rate, double years, double amount)
{
     double displayAmount;
     cout << "After" << years << "years at interest rate" << rate << "%, $" << principal <<  "will become $" << computeAmount <<"." << endl;
     }






There is a * missing line 80.
computeAmount needs arguments on line 92, or to be called somewhere and make the variable global to use it in cout like that.
Also, i'm not sure how the compiler apreciates to have a variable called like the function it is in.

For next time, please tell us what the error is if you want faster help
22 . too few arguments to function `double computeAmount(double, double, double)'
What do you think that means?

Function prototype:

double computeAmount(double principal, double rate, double years);

Function call from main:

computeAmount();

Same for displayAmount, you give three parameters in your declarations, but when you make the call, you pass no parameters which isn't allowed.
closed account (zb0S216C)
The compiler is getting confused. In function computeAmount( ), you've declared a local variable that has the same identifier as computeAmount( ). It's ambiguous. Either rename your function identifier or the variable.

Wazzak
Last edited on
ok so i added
1
2
3
4
5
6
 
    getPrincipal();
    getRate();
    getYears();
     computeAmount(double principal, double rate, double years);
    displayAmount(double principal, double rate, double years, double amount);


and im getting multiple of:
38. expected primary-expression before "double"
39. expected primary-expression before "double"
92. variable or field `displayAmount' declared void
93. [Warning] the address of `double computeAmount(double, double, double)', will always evaluate as `true'
94. return-statement with a value, in function returning 'void'

things like this always happen to me and idk what i do so wrong... its prob just my add that makes the obvious very hard
closed account (zb0S216C)
Functions need a return type-specifier, that is, a return type. The compiler will either assume void or int, depending on the compiler. The basic function takes this form:

[TYPE-SPECIFIER] [IDENTIFIER] ( [PARAMETER_LIST] );

Wazzak
Topic archived. No new replies allowed.