currency interest program need help coding it further

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2006
Posts: 10
Reputation: sunny123 is an unknown quantity at this point 
Solved Threads: 0
sunny123 sunny123 is offline Offline
Newbie Poster

currency interest program need help coding it further

 
0
  #1
Nov 22nd, 2006
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;
}
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,442
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1474
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: currency interest program need help coding it further

 
0
  #2
Nov 22nd, 2006
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: currency interest program need help coding it further

 
0
  #3
Nov 22nd, 2006
[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)

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.
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 10
Reputation: sunny123 is an unknown quantity at this point 
Solved Threads: 0
sunny123 sunny123 is offline Offline
Newbie Poster

Re: currency interest program need help coding it further

 
0
  #4
Nov 22nd, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 10
Reputation: sunny123 is an unknown quantity at this point 
Solved Threads: 0
sunny123 sunny123 is offline Offline
Newbie Poster

Re: currency interest program need help coding it further

 
0
  #5
Nov 22nd, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: currency interest program need help coding it further

 
1
  #6
Nov 22nd, 2006
Originally Posted by sunny123 View Post
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.
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 10
Reputation: sunny123 is an unknown quantity at this point 
Solved Threads: 0
sunny123 sunny123 is offline Offline
Newbie Poster

Re: currency interest program need help coding it further

 
0
  #7
Nov 23rd, 2006
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

  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
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: currency interest program need help coding it further

 
0
  #8
Nov 23rd, 2006
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
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 10
Reputation: sunny123 is an unknown quantity at this point 
Solved Threads: 0
sunny123 sunny123 is offline Offline
Newbie Poster

Re: currency interest program need help coding it further

 
0
  #9
Nov 24th, 2006
thanks that helps alot
i will implement those changes and see what happens
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 10
Reputation: sunny123 is an unknown quantity at this point 
Solved Threads: 0
sunny123 sunny123 is offline Offline
Newbie Poster

Re: currency interest program need help coding it further

 
0
  #10
Nov 25th, 2006
Originally Posted by joeprogrammer View Post
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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC