hello everyone whats wrong with my code?

hi everyone
the embeded algorithm was done by my teacher and i implemented the code... what are my errors?.. thanks!


// Pseudocode PLD Chapter 9 #3 pg. 400
// Name: Liat Ledder
// Email: ledder.liat@titans.easternflorida.edu
// Purpose:
//
// Start
#include <iostream>
#include <cstdlib>

using namespace std;

int main( )
{
// Declarations
// num amount
// num newAmount
// num interestRate

int amount;
int newAmount;
int 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

cout << "Please enter dollar amount. " << endl;
cin >> amount;
cout << "Please enter the interest rate(e.g., nine percent should be entered as 0.9). " << endl;
cin >> interestRate;
// newAmount = FutureValue(amount,interestRate)
// output "The new dollar amount is ", newAmount
// Stop
//

newAmount = FutureValue(amount,interestRate);
cout << "The new dollar amount is ", newAmount

return 0;
}
// num FutureValue(num initialAmount, num interestRate)
// Declarations
// num finalAmount
// finalAmount = (1 + interestRate/100) * initialAmount
// return finalAmount

int main()
{
int FutureValue(int initialAmount >> int interestRate);
int finalAmount;
finalAmount = (1+ interestRate/100) * initialAmount;
return final Amount;
system("PAUSE");
return 0;
}
use code tags please.

1. erm.. you have two main() functions. that's wrong.

2. return final Amount;
This make no sense. Even if the syntax is right, why do you write more code after returning from your (second!) main?

3. int FutureValue(int initialAmount >> int interestRate);

is nonsense too.

Basically a lot of this is very bad incorrect syntax.

If you want to know your errors, your compiler should tell you a lot of what i've mentioned.
Last edited on
sorry... i hope this is better




// Pseudocode PLD Chapter 9 #3 pg. 400
// Name: Liat Ledder
// Email: ledder.liat@titans.easternflorida.edu
// Purpose:
//
// Start
#include <iostream>
#include <cstdlib>

using namespace std;

int main( )
{
// Declarations
// num amount
// num newAmount
// num interestRate

int amount;
int newAmount;
int 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

cout << "Please enter dollar amount. " << endl;
cin >> amount;
cout << "Please enter the interest rate(e.g., nine percent should be entered as 0.9). " << endl;
cin >> interestRate;
// newAmount = FutureValue(amount,interestRate)
// output "The new dollar amount is ", newAmount
// Stop
//

newAmount = FutureValue(amount,interestRate);
cout << "The new dollar amount is ", newAmount

return 0;
}
// num FutureValue(num initialAmount, num interestRate)
// Declarations
// num finalAmount
// finalAmount = (1 + interestRate/100) * initialAmount
// return finalAmount

int main()
{
int FutureValue(int initialAmount >> int interestRate);
int finalAmount;
finalAmount = (1+ interestRate/100) * initialAmount;
return final Amount;
system("PAUSE");
return 0;
}
oh no... i dont know why its doing it... it looks better before i click submit then it changes
What are you errors?

Did you try compiling it? A compiler will tell you your errors.

Line 36: No forward declarations for FutureValue.
Line 37: Improper use of , operator. No ;
Line 12, 47: Multiple declarations of main(). A program can have only one main().
Line 49: What is the >> operator supposed to be doing here? It's neither an input operation nor a shift operation. This whole statement is messed up.
Line 52: finalAmount misspelled (no space).
Line 53: This statement will never be executed.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
Hint: You can edit your previous post, highlight you code and press the <> formatting button.
Last edited on
OP did you even read anything i wrote?
Thank you. I tried to correct it to the best of my understanding... Im sorry im just new and dont know much... i do see the complier errors but they dont always make sense to me...here is what i tried to correct..

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
// Pseudocode PLD Chapter 9 #3 pg. 400
// Name: Liat Ledder
// Email: ledder.liat@titans.easternflorida.edu
// Purpose:
//    
// Start
#include <iostream>
#include <cstdlib>

using namespace std;

int main( )
{
//     Declarations
//       num amount
//       num newAmount
//       num interestRate
        

    int amount;
    int newAmount;
    int interestRate;
    int futureValue;
//     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

  cout << "Please enter dollar amount.  " << endl;
  cin >> amount;
  cout << "Please enter the interest rate(e.g., nine percent should be entered as 0.9).  " << endl;
  cin >> interestRate;
//     newAmount = futureValue(amount,interestRate)
//     output "The new dollar amount is ", newAmount
// Stop
//

  newAmount = futureValue(amount,interestRate);
  cout << "The new dollar amount is " << newAmount;

return 0;
}
// num FutureValue(num initialAmount, num interestRate)
//     Declarations
//       num finalAmount
//     finalAmount = (1 + interestRate/100) * initialAmount
// return finalAmount


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

return 0;
mutexe (1088) im sorry i replied before seeing your answer
You need to put curly braces for futureValue() and remove the semicolon like this:
1
2
3
4
5
int futureValue(int initialAmount, int interestRate) {
      int finalAmount;
     finalAmount = (1+ interestRate/100) * initialAmount;
   return finalAmount;
}


And you will also need to define a prototype for futureValue() above the main() function like this:
int futureValue(int initialAmount, int interestRate);

Edit: You also have a return 0; on the last line that needs to be removed.
Last edited on
Thank you for that:)... Its still giving me errors im not sure why:(

// Pseudocode PLD Chapter 9 #3 pg. 400
// Name: Liat Ledder
// Email: ledder.liat@titans.easternflorida.edu
// Purpose:
//
// Start
#include <iostream>
#include <cstdlib>

using namespace std;
int futureValue(int initialAmount, int interestRate);

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
int main( )
{
//     Declarations
//       num amount
//       num newAmount
//       num interestRate
        

    int amount;
    int newAmount;
    int interestRate;
    int futureValue;
//     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

  cout << "Please enter dollar amount.  " << endl;
  cin >> amount;
  cout << "Please enter the interest rate(e.g., nine percent should be entered as 0.9).  " << endl;
  cin >> interestRate;
//     newAmount = futureValue(amount,interestRate)
//     output "The new dollar amount is ", newAmount
// Stop
//

  newAmount = futureValue(amount,interestRate);
  cout << "The new dollar amount is " << newAmount;

return 0;
}
// num FutureValue(num initialAmount, num interestRate)
//     Declarations
//       num finalAmount
//     finalAmount = (1 + interestRate/100) * initialAmount
// return finalAmount


int futureValue(int initialAmount, int interestRate)
{

      int finalAmount;
     finalAmount = (1+ interestRate/100) * initialAmount;
   return finalAmount;
}



You need to create a function prototype above main for futerValue, or move the futureValue function above main.

Line 12 you have a variable name the same as your function name.

Line 15 tells you you would be inputting the interest rate with support for a decimal point yet your variable interestRate is assigned as a int. The same goes for amount and finalAmount, I would hazard a guess these also need to be a float.

FutureValue, would also need to return a float and not an int.
Its still giving me errors im not sure

What errors?

Line 12: futureValue is a local int. That symbol takes precedence over the function prototype. Line 27: You can't call an int.






Just to extend on my post above, the function futureValue should not accept int as its parameters.
^ What they said, and I don't see a reason to include cstdlib on your code right now, unless I am missing something.

So putting all that advice together in one post..........

Remove line 12 ( int futureValue; )
Change all int to float : http://www.cplusplus.com/doc/tutorial/variables/
Add your function prototype at the top above main : http://www.cplusplus.com/doc/tutorial/functions/

and you don't need cstdlib as programmerdog297 stated so that can be removed.

Job done :)
Thank you. I have made the suggested changes.. now the complier is highlighting the last pair of curly braces

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
// Pseudocode PLD Chapter 9 #3 pg. 400
// Name: Liat Ledder
// Email: ledder.liat@titans.easternflorida.edu
// Purpose:
//    
// Start
#include <iostream>
#include <cstdlib>

using namespace std;
float futureValue(int initialAmount, int interestRate);

int main( )
{
//     Declarations
//       num amount
//       num newAmount
//       num interestRate
        

    double amount;
    int newAmount;
    double 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

  cout << "Please enter dollar amount.  " << endl;
  cin >> amount;
  cout << "Please enter the interest rate(e.g., nine percent should be entered as 0.9).  " << endl;
  cin >> interestRate;
//     newAmount = futureValue(amount,interestRate)
//     output "The new dollar amount is ", newAmount
// Stop
//

  newAmount = futureValue(amount,interestRate);
  cout << "The new dollar amount is " << newAmount;

return 0;
}
// num FutureValue(num initialAmount, num interestRate)
//     Declarations
//       num finalAmount
//     finalAmount = (1 + interestRate/100) * initialAmount
// return finalAmount



{
      double finalAmount;
     finalAmount = (1+ interestRate/100) * initialAmount;

   return finalAmount;
}


You still need this above the futureValue() function on line 51:
1
2
3
4
5
6
7
float futureValue(int initialAmount, int interestRate)
{
      double finalAmount;
     finalAmount = (1+ interestRate/100) * initialAmount;

   return finalAmount;
}


You will also need to change the initialAmount and interestRate parameters to floats in the function prototype and declaration.
thanks for everything!:)

You still have problems in your last post's source code and haven't taken my advice.

Line 22 declared as an int, function would return a float if going by my previous advice (all ints to floats - or even doubles if you prefer).
Topic archived. No new replies allowed.