| | |
currency interest program need help coding it further
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2006
Posts: 10
Reputation:
Solved Threads: 0
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;
}
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;
}
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.
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.
[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
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)
Perhaps the "interest" is the penalty for changing currencies... banks never give you the full conversion rate when exchanging currencies.
Hope this helps
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?
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.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
Join Date: Oct 2006
Posts: 10
Reputation:
Solved Threads: 0
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
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
•
•
•
•
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.
"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.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
Join Date: Oct 2006
Posts: 10
Reputation:
Solved Threads: 0
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
coding shown below
C++ Syntax (Toggle Plain Text)
#include <iostream.h> //function declarations void inputAmount(int&); int calCommission(int,int, int); int main() {//start of function main int gbp; int usd; int euro; inputAmount (gbp); commission= calCommission(gbp,usd,euro); }//end of function main //definition of function inputAmount void inputAmount (int&gbp) int select= 0; {//start of function inputAmount 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; } else if (select == 2) { cout <<" Enter amount in Pounds to convert to Euro: "; cin >> gbp; } else cout << "Valid options 1 or 2." << endl; return 0; }//end of function inputAmount //definition of function calCommission int calCommission(int usd, int euro) {//start of function calCommission if (select==1 and gbp <= 1000) commission= (usd or euro)+(usd or euro)*0.01) cout<<"Total Amount after commision:£"<<total; } else if (select==2 and gbp >1000) commission= (usd or euro)+(usd or euro)*0.03) cout<<"Total Amount after commision:£"<<total; }//end of function calCommission
Last edited by ~s.o.s~; Nov 24th, 2006 at 2:11 am. Reason: Fixed code tags
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.
In your main function:
Where did
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.
Also, I'm noticing that you're trying to use
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:
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
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 maincommission 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;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 calCommissionHope 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.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
Join Date: Oct 2006
Posts: 10
Reputation:
Solved Threads: 0
•
•
•
•
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 statementusing namespace std;after including iostream.
In your main function:
Where didint 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 maincommissioncome 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.
Also, I'm noticing that you're trying to usevoid inputAmount (int&gbp) int select= 0; {//start of function inputAmount cout << "Please select from the following: " << endl;selectinside 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:
As you can see, there are a number of errors in the code ^_^. I've commented the errors so you can see them.//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
Hope this helps
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Tokeniser
- Next Thread: Definitions of several typedef types?!?
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






