943,553 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2865
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Nov 22nd, 2006
0

currency interest program need help coding it further

Expand Post »
ive created this currency interest preogram which should calculate the interest depending on the currency amount entered.

if 100 but less than 1000 then 1%, otherwise 3% for all other amounts.

can someone give me any ideas as how to start the interest part of the program off, and which variables i might need to declare in order to caslculate the interest.

ive done the first part where it asks the user for what amount to be converted to which currency.

any help appreciated coding shown below

#include <iostream.h>
int main()
{
int gbp;
int usd;
int euro;
int select = 0;
cout << "Please select from the following: " << endl;
cout << "1) Pounds to US doller" << endl;
cout << "2) Pounds to Euro" << endl << endl;
cout << "Enter: ";
cin >> select;
if (select == 1)
{
cout << " Enter amount in Pounds to convert to Dollers: ";
cin >> gbp;
usd = (gbp*1.5);
cout << "Equivalent in Dollers is: " << usd << endl;
}
else if (select == 2)
{
cout <<" Enter amount in Pounds to convert to Euro: ";
cin >> gbp;
euro = (gbp*1.6);
cout << "Equivalent in euros is: " << euro << endl;
}
else
cout << "Valid options 1 or 2." << endl;
return 0;
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sunny123 is offline Offline
10 posts
since Oct 2006
Nov 22nd, 2006
0

Re: currency interest program need help coding it further

I'm confused -- you said you want an interest program but you wrote a currency conversion program. which is it?

Please edit your post to use code tags as described in the link in my signature.

you might first try doing the interest part with pencil & paper. Just write down what question you want to ask and then how to calculate the interest. hint: interest = principal times interest rate. Variable can not be integers because integers to not have decimal places.
Last edited by Ancient Dragon; Nov 22nd, 2006 at 7:19 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Nov 22nd, 2006
0

Re: currency interest program need help coding it further

[edit](Nevermind)[/edit] Please use code tags. It makes code easier to read.

First of all, your menu looks correct, although you might want to use a switch {} statement, instead of if to make the code more readable.

Inside each menu option, use a double to keep track of the interest rate. Use an if () statement to determine the interest rate. Once you've done that, calculating the final result should not be difficult. (total = (usd or euro) + (usd or euro)*interest)

Quote originally posted by Ancient Dragon ...
I'm confused -- you said you want an interest program but you wrote a currency conversion program. which is it?
Perhaps the "interest" is the penalty for changing currencies... banks never give you the full conversion rate when exchanging currencies.

Hope this helps
Last edited by John A; Nov 22nd, 2006 at 7:23 pm.
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006
Nov 22nd, 2006
0

Re: currency interest program need help coding it further

its supposed to be a currency conversion program
but once the program has converted the currency it should then work out the interest rate depending on the amount converted.
example if £100 converted to USD then interest rate will be added on of 1% to the £100 to give final amount after interest.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sunny123 is offline Offline
10 posts
since Oct 2006
Nov 22nd, 2006
0

Re: currency interest program need help coding it further

ok will try it
i plan to put the program, into three functions one to prompt the user for the amount and currency to be converted into
the second function to do the calculation and interest calculation
and the third to display it in a certain way.

once ive put it into functions i will see how it goes and hopefully i wont have any problems
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sunny123 is offline Offline
10 posts
since Oct 2006
Nov 22nd, 2006
1

Re: currency interest program need help coding it further

Click to Expand / Collapse  Quote originally posted by sunny123 ...
its supposed to be a currency conversion program
but once the program has converted the currency it should then work out the interest rate depending on the amount converted.
example if £100 converted to USD then interest rate will be added on of 1% to the £100 to give final amount after interest.
OK, then do what Mr. Dragon and I suggested. Work it out with pencil and paper, and use a double to keep track of the intereset rates. Remember, if you multiply the amount of money by the interest rate, the interest rate will have to be 1/100 of the amount in the percentage. For example, 5% would be 0.05. Then you add the amount of money to that result. Or you can eliminate the need to add the amount of money to the result by adding 1 to the interest rate before multiplying. Hope this makes sense.
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006
Nov 23rd, 2006
0

Re: currency interest program need help coding it further

ive now put the program into functions ut ive got errors saying undefined symbol commission in function main? dont know how to fix it can someone help me, dont know whether the function structure might be wrong.
coding shown below

C++ Syntax (Toggle Plain Text)
  1. #include <iostream.h>
  2.  
  3. //function declarations
  4. void inputAmount(int&);
  5. int calCommission(int,int, int);
  6. int main()
  7. {//start of function main
  8. int gbp;
  9. int usd;
  10. int euro;
  11. inputAmount (gbp);
  12. commission= calCommission(gbp,usd,euro);
  13. }//end of function main
  14.  
  15. //definition of function inputAmount
  16. void inputAmount (int&gbp)
  17. int select= 0;
  18. {//start of function inputAmount
  19. cout << "Please select from the following: " << endl;
  20. cout << "1) Pounds to US doller" << endl;
  21. cout << "2) Pounds to Euro" << endl << endl;
  22. cout << "Enter: ";
  23. cin >> select;
  24. if (select == 1)
  25. {
  26. cout << " Enter amount in Pounds to convert to Dollers: ";
  27. cin >> gbp;
  28. }
  29. else if (select == 2)
  30. {
  31. cout <<" Enter amount in Pounds to convert to Euro: ";
  32. cin >> gbp;
  33. }
  34. else
  35. cout << "Valid options 1 or 2." << endl;
  36. return 0;
  37. }//end of function inputAmount
  38.  
  39.  
  40. //definition of function calCommission
  41. int calCommission(int usd, int euro)
  42. {//start of function calCommission
  43. if (select==1 and gbp <= 1000)
  44. commission= (usd or euro)+(usd or euro)*0.01)
  45. cout<<"Total Amount after commision:£"<<total;
  46. }
  47. else if (select==2 and gbp >1000)
  48. commission= (usd or euro)+(usd or euro)*0.03)
  49. cout<<"Total Amount after commision:£"<<total;
  50. }//end of function calCommission
Last edited by ~s.o.s~; Nov 24th, 2006 at 2:11 am. Reason: Fixed code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sunny123 is offline Offline
10 posts
since Oct 2006
Nov 23rd, 2006
0

Re: currency interest program need help coding it further

Just to let you know, BBCode tags have a starting and ending tag. Put [code] at the beginning of your code, and [/code] at the end of your code. (At the moment, you didn't put a proper closing tag on your code, which is why they didn't display properly.)

I see you are using degraded and old coding styles. #include <iostream.h> should be #include <iostream>, and then either prefixing all Standard Template Library objects with std::, or using the statement using namespace std; after including iostream.

In your main function:
int main()
{//start of function main
    int gbp;
    int usd;
    int euro;
    inputAmount (gbp); // shouldn't it be inputAmount(&gbp) ?
    commission= calCommission(gbp,usd,euro); // why are you passing 3 parameters to a 2-parameter function?
}//end of function main
Where did commission come from? You never declared it, so of course the compiler will give errors on that.

Remember, all instructions/statements must be inside the function, unless you meant it to be global, in which case it should not be sandwiched in between inputAmount() and the starting brace. However, if you would follow my recommendation, move it inside the function so it's not global.
void inputAmount (int&gbp)
int select= 0;
{//start of function inputAmount
cout << "Please select from the following: " << endl;
Also, I'm noticing that you're trying to use select inside of calCommission(). This does not work, because it was (should have been) declared inside of inputAmount(). Your best option right now is to make inputAmount() return the selection, and use this as a parameter for calComission().

That way, you're using proper programming practices and not using globals.

In calCommission, there's this variable you're using called "commission", which you never declared. Also:
//definition of function calCommission
int calCommission(int usd, int euro)
{//start of function calCommission
if (select==1 and gbp <= 1000) // missing '{'
commission= (usd or euro)+(usd or euro)*0.01) // missing ';'
cout<<"Total Amount after commision:£"<<total;
}
else if (select==2 and gbp >1000) // missing '{'
commission= (usd or euro)+(usd or euro)*0.03) // missing ';'
cout<<"Total Amount after commision:£"<<total;
}//end of function calCommission
As you can see, there are a number of errors in the code ^_^. I've commented the errors so you can see them.

Hope this helps
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006
Nov 24th, 2006
0

Re: currency interest program need help coding it further

thanks that helps alot
i will implement those changes and see what happens
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sunny123 is offline Offline
10 posts
since Oct 2006
Nov 25th, 2006
0

Re: currency interest program need help coding it further

Just to let you know, BBCode tags have a starting and ending tag. Put [code] at the beginning of your code, and [/code] at the end of your code. (At the moment, you didn't put a proper closing tag on your code, which is why they didn't display properly.)

I see you are using degraded and old coding styles. #include <iostream.h> should be #include <iostream>, and then either prefixing all Standard Template Library objects with std::, or using the statement using namespace std; after including iostream.

In your main function:
int main()
{//start of function main
    int gbp;
    int usd;
    int euro;
    inputAmount (gbp); // shouldn't it be inputAmount(&gbp) ?
    commission= calCommission(gbp,usd,euro); // why are you passing 3 parameters to a 2-parameter function?
}//end of function main
Where did commission come from? You never declared it, so of course the compiler will give errors on that.

Remember, all instructions/statements must be inside the function, unless you meant it to be global, in which case it should not be sandwiched in between inputAmount() and the starting brace. However, if you would follow my recommendation, move it inside the function so it's not global.
void inputAmount (int&gbp)
int select= 0;
{//start of function inputAmount
cout << "Please select from the following: " << endl;
Also, I'm noticing that you're trying to use select inside of calCommission(). This does not work, because it was (should have been) declared inside of inputAmount(). Your best option right now is to make inputAmount() return the selection, and use this as a parameter for calComission().

That way, you're using proper programming practices and not using globals.

In calCommission, there's this variable you're using called "commission", which you never declared. Also:
//definition of function calCommission
int calCommission(int usd, int euro)
{//start of function calCommission
if (select==1 and gbp <= 1000) // missing '{'
commission= (usd or euro)+(usd or euro)*0.01) // missing ';'
cout<<"Total Amount after commision:£"<<total;
}
else if (select==2 and gbp >1000) // missing '{'
commission= (usd or euro)+(usd or euro)*0.03) // missing ';'
cout<<"Total Amount after commision:£"<<total;
}//end of function calCommission
As you can see, there are a number of errors in the code ^_^. I've commented the errors so you can see them.

Hope this helps
how would i make inputAmount return the selection, and use this as a parameter for calCommision?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sunny123 is offline Offline
10 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Tokeniser
Next Thread in C++ Forum Timeline: Definitions of several typedef types?!?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC