473,414 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

write small currency converter

Hello
My country Ghana is changing its currency. I want to write a small
programme in C++ that can covert from the old currency into the new
one. I would like this programme to run behind a simple calculator-
looking interface. I'm quite new to C++, and I would need some help.
Please any suggestion is welcome :)

The following is what I have been able to do so far:
#include <iostream>
using namespace std;

int main(){
//variables declared

int old_currency_value, new_currency_value, result_of_formula;

//questions to ask user

cout<< "Please enter the value of the old currency you wish to
convert";
cin >old_currency_value;

//conversion implementation
new_currency_value = old_currency_value/10000;

cout << "The value of the new currency is " << new_currency_value <<
endl;

//quit programme

return 0;

Jul 3 '07 #1
25 5901
"mereba" <jo**********@gmail.comwrote in message
news:11**********************@m36g2000hse.googlegr oups.com...
Hello
My country Ghana is changing its currency. I want to write a small
programme in C++ that can covert from the old currency into the new
one. I would like this programme to run behind a simple calculator-
looking interface. I'm quite new to C++, and I would need some help.
Please any suggestion is welcome :)

The following is what I have been able to do so far:
#include <iostream>
using namespace std;

int main(){
//variables declared

int old_currency_value, new_currency_value, result_of_formula;

//questions to ask user

cout<< "Please enter the value of the old currency you wish to
convert";
cin >old_currency_value;

//conversion implementation
new_currency_value = old_currency_value/10000;

cout << "The value of the new currency is " << new_currency_value <<
endl;

//quit programme

return 0;
So what is your question?
Jul 3 '07 #2
On Jul 3, 10:30 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
"mereba" <jojoo.imb...@gmail.comwrote in message

news:11**********************@m36g2000hse.googlegr oups.com...
Hello
My country Ghana is changing its currency. I want to write a small
programme in C++ that can covert from the old currency into the new
one. I would like this programme to run behind a simple calculator-
looking interface. I'm quite new to C++, and I would need some help.
Please any suggestion is welcome :)
The following is what I have been able to do so far:
#include <iostream>
using namespace std;
int main(){
//variables declared
int old_currency_value, new_currency_value, result_of_formula;
//questions to ask user
cout<< "Please enter the value of the old currency you wish to
convert";
cin >old_currency_value;
//conversion implementation
new_currency_value = old_currency_value/10000;
cout << "The value of the new currency is " << new_currency_value <<
endl;
//quit programme
return 0;

So what is your question?
Thanks for your quick response

1. How do I write a gui in C++ for this programme?
2. Do you have any suggestions for enhancing this programme?

Jul 3 '07 #3
"mereba" <jo**********@gmail.comwrote in message
news:11**********************@m36g2000hse.googlegr oups.com...
On Jul 3, 10:30 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
>"mereba" <jojoo.imb...@gmail.comwrote in message

news:11**********************@m36g2000hse.googleg roups.com...
Hello
My country Ghana is changing its currency. I want to write a small
programme in C++ that can covert from the old currency into the new
one. I would like this programme to run behind a simple calculator-
looking interface. I'm quite new to C++, and I would need some help.
Please any suggestion is welcome :)
The following is what I have been able to do so far:
#include <iostream>
using namespace std;
int main(){
//variables declared
int old_currency_value, new_currency_value, result_of_formula;
//questions to ask user
cout<< "Please enter the value of the old currency you wish to
convert";
cin >old_currency_value;
//conversion implementation
new_currency_value = old_currency_value/10000;
cout << "The value of the new currency is " << new_currency_value <<
endl;
//quit programme
return 0;

So what is your question?

Thanks for your quick response

1. How do I write a gui in C++ for this programme?
GUI is beyond the scope of this newsgroup, it is platform dependant. Ask in
a newsgroup dedicated to your OS/platform (alt.windows...etc.., alt.linux,
whatever).
2. Do you have any suggestions for enhancing this programme?
Write a GUI for it. Of course, you'll need to get information somewhere,
try in a newsgroup for your OS
Jul 3 '07 #4
On Jul 3, 10:58 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
"mereba" <jojoo.imb...@gmail.comwrote in message

news:11**********************@m36g2000hse.googlegr oups.com...
On Jul 3, 10:30 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
"mereba" <jojoo.imb...@gmail.comwrote in message
>news:11**********************@m36g2000hse.googleg roups.com...
Hello
My country Ghana is changing its currency. I want to write a small
programme in C++ that can covert from the old currency into the new
one. I would like this programme to run behind a simple calculator-
looking interface. I'm quite new to C++, and I would need some help.
Please any suggestion is welcome :)
The following is what I have been able to do so far:
#include <iostream>
using namespace std;
int main(){
//variables declared
int old_currency_value, new_currency_value, result_of_formula;
//questions to ask user
cout<< "Please enter the value of the old currency you wish to
convert";
cin >old_currency_value;
//conversion implementation
new_currency_value = old_currency_value/10000;
cout << "The value of the new currency is " << new_currency_value <<
endl;
//quit programme
return 0;
So what is your question?
Thanks for your quick response
1. How do I write a gui in C++ for this programme?

GUI is beyond the scope of this newsgroup, it is platform dependant. Ask in
a newsgroup dedicated to your OS/platform (alt.windows...etc.., alt.linux,
whatever).
2. Do you have any suggestions for enhancing this programme?

Write a GUI for it. Of course, you'll need to get information somewhere,
try in a newsgroup for your OS
Jim,
I'm using Gtk, and I thought code was code? Thanks for your
suggestions, but can I not get any real direct answers to my
questions?
Jul 3 '07 #5
mereba wrote:
Hello
My country Ghana is changing its currency. I want to write a small
programme in C++ that can covert from the old currency into the new
one. I would like this programme to run behind a simple calculator-
looking interface. I'm quite new to C++, and I would need some help.
Please any suggestion is welcome :)

The following is what I have been able to do so far:
#include <iostream>
using namespace std;

int main(){
//variables declared

int old_currency_value, new_currency_value, result_of_formula;
are you sure that an integer will suit? in some machine the integer
range is not so big. And you may want to store decimal digits.

//questions to ask user

cout<< "Please enter the value of the old currency you wish to
convert";
cin >old_currency_value;

//conversion implementation
new_currency_value = old_currency_value/10000;
if old currency value was 19999, new_currency_value would be 1. Are you
sure that you want this to happen?
For a GUI, I'll suggest you to use qt. But beware: it's not as easy as
writing a simple console program!

Regards,

Zeppe
Jul 3 '07 #6
On Jul 3, 12:26 pm, Zeppe
<zep_p@.remove.all.this.long.comment.yahoo.itwrote :
mereba wrote:
Hello
My country Ghana is changing its currency. I want to write a small
programme in C++ that can covert from the old currency into the new
one. I would like this programme to run behind a simple calculator-
looking interface. I'm quite new to C++, and I would need some help.
Please any suggestion is welcome :)
The following is what I have been able to do so far:
#include <iostream>
using namespace std;
int main(){
//variables declared
int old_currency_value, new_currency_value, result_of_formula;

are you sure that an integer will suit? in some machine the integer
range is not so big. And you may want to store decimal digits.
//questions to ask user
cout<< "Please enter the value of the old currency you wish to
convert";
cin >old_currency_value;
//conversion implementation
new_currency_value = old_currency_value/10000;

if old currency value was 19999, new_currency_value would be 1. Are you
sure that you want this to happen?

For a GUI, I'll suggest you to use qt. But beware: it's not as easy as
writing a simple console program!

Regards,

Zeppe
Thanks to all who made suggestions. Thank you to Zeppe for your
advice. I'm changing all the data types to double. Thanks for the
suggestion to use qt. Any more suggestions on improving this basic
code is welcome.

Jul 3 '07 #7
mereba <jo**********@gmail.comwrote:
My country Ghana is changing its currency. I want to write a small
programme in C++ that can covert from the old currency into the new
one. I would like this programme to run behind a simple calculator-
looking interface. I'm quite new to C++, and I would need some help.
Please any suggestion is welcome :)
Frankly, it sounds like homework. Google, "Ghana currency converter" and
you will find dozens of them.
The following is what I have been able to do so far:
#include <iostream>
using namespace std;

int main(){
//variables declared

int old_currency_value, new_currency_value, result_of_formula;

//questions to ask user

cout<< "Please enter the value of the old currency you wish to
convert";
cin >old_currency_value;

//conversion implementation
new_currency_value = old_currency_value/10000;

cout << "The value of the new currency is " << new_currency_value <<
endl;

//quit programme

return 0;
Your missing the close paren at the end, otherwise your program will
compile and run. Is the output what you expected?
Jul 3 '07 #8
On Jul 3, 1:35 pm, "Daniel T." <danie...@earthlink.netwrote:
mereba <jojoo.imb...@gmail.comwrote:
My country Ghana is changing its currency. I want to write a small
programme in C++ that can covert from the old currency into the new
one. I would like this programme to run behind a simple calculator-
looking interface. I'm quite new to C++, and I would need some help.
Please any suggestion is welcome :)

Frankly, it sounds like homework. Google, "Ghana currency converter" and
you will find dozens of them.
The following is what I have been able to do so far:
#include <iostream>
using namespace std;
int main(){
//variables declared
int old_currency_value, new_currency_value, result_of_formula;
//questions to ask user
cout<< "Please enter the value of the old currency you wish to
convert";
cin >old_currency_value;
//conversion implementation
new_currency_value = old_currency_value/10000;
cout << "The value of the new currency is " << new_currency_value <<
endl;
//quit programme
return 0;

Your missing the close paren at the end, otherwise your program will
compile and run. Is the output what you expected?
This is no joke Daniel T :).My country is CHANGING its currency. I'm
not looking for some fancy converters from the old Ghana cedi to US
dollars and other currencies. I'm looking to write my own programme
that can convert from the old Ghana cedi to the NEW Ghana cedi, and I
intend to do just that with C++. Thanks for the tip about closing
parentheses. It is well noted. Please more suggestions are welcome.
The source code now looks like this:

#include <iostream>
using namespace std;

int main(){
//variables declared

double old_currency_value, new_currency_value, result_of_formula;
double value_in_pessewas; //datatypes changed to double. suggested by
Zeppe of
//comp.lang.c++ google group

//questions to ask user

cout<< "Please enter the value of the old currency you wish to convert
" << endl;
cin >old_currency_value;

//conversion implementation
if (old_currency_value<10000){ //suggested by Reuben
value_in_pessewas= old_currency_value/100;
new_currency_value= value_in_pessewas;
}
else
new_currency_value = old_currency_value/10000;

cout << "The value of the new currency is " << new_currency_value <<
endl;

//quit programme
return 0;
}

Jul 3 '07 #9
On 2007-07-03 17:23, mereba wrote:
On Jul 3, 1:35 pm, "Daniel T." <danie...@earthlink.netwrote:
>mereba <jojoo.imb...@gmail.comwrote:
My country Ghana is changing its currency. I want to write a small
programme in C++ that can covert from the old currency into the new
one. I would like this programme to run behind a simple calculator-
looking interface. I'm quite new to C++, and I would need some help.
Please any suggestion is welcome :)

Frankly, it sounds like homework. Google, "Ghana currency converter" and
you will find dozens of them.
The following is what I have been able to do so far:
#include <iostream>
using namespace std;
int main(){
//variables declared
int old_currency_value, new_currency_value, result_of_formula;
//questions to ask user
cout<< "Please enter the value of the old currency you wish to
convert";
cin >old_currency_value;
//conversion implementation
new_currency_value = old_currency_value/10000;
cout << "The value of the new currency is " << new_currency_value <<
endl;
//quit programme
return 0;

Your missing the close paren at the end, otherwise your program will
compile and run. Is the output what you expected?

This is no joke Daniel T :).My country is CHANGING its currency. I'm
not looking for some fancy converters from the old Ghana cedi to US
dollars and other currencies. I'm looking to write my own programme
that can convert from the old Ghana cedi to the NEW Ghana cedi, and I
intend to do just that with C++. Thanks for the tip about closing
parentheses. It is well noted. Please more suggestions are welcome.
The source code now looks like this:
Looks quite good, there is one problem though, if I input 5000 and
500000 I get the same result (50) because you don't tell the user the
type of the answer.

Also notice that the variable result_of_formula is never used so you can
delete it. You can also, if you wish, get rid of the variables
new_currency_value and value_in_pessewas by performing the calculations
in the if-statement, like this:

#include <iostream>
using namespace std;

int main() {
double old;

cout << "Please enter the value of the old currency"
"you wish to convert" << endl;
cin >old;

if (old < 10000) {
cout << "The value of the new currency is "
<< old / 100 << " pessewas" << endl;
}
else {
cout << "The value if the new currency is "
<< old / 10000 << " cedi" << endl;
}
return 0;
}

--
Erik Wikström
Jul 3 '07 #10
On Jul 3, 5:11 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-07-03 17:23, mereba wrote:
On Jul 3, 1:35 pm, "Daniel T." <danie...@earthlink.netwrote:
mereba <jojoo.imb...@gmail.comwrote:
My country Ghana is changing its currency. I want to write a small
programme in C++ that can covert from the old currency into the new
one. I would like this programme to run behind a simple calculator-
looking interface. I'm quite new to C++, and I would need some help.
Please any suggestion is welcome :)
Frankly, it sounds like homework. Google, "Ghana currency converter" and
you will find dozens of them.
The following is what I have been able to do so far:
#include <iostream>
using namespace std;
int main(){
//variables declared
int old_currency_value, new_currency_value, result_of_formula;
//questions to ask user
cout<< "Please enter the value of the old currency you wish to
convert";
cin >old_currency_value;
//conversion implementation
new_currency_value = old_currency_value/10000;
cout << "The value of the new currency is " << new_currency_value <<
endl;
//quit programme
return 0;
Your missing the close paren at the end, otherwise your program will
compile and run. Is the output what you expected?
This is no joke Daniel T :).My country is CHANGING its currency. I'm
not looking for some fancy converters from the old Ghana cedi to US
dollars and other currencies. I'm looking to write my own programme
that can convert from the old Ghana cedi to the NEW Ghana cedi, and I
intend to do just that with C++. Thanks for the tip about closing
parentheses. It is well noted. Please more suggestions are welcome.
The source code now looks like this:

Looks quite good, there is one problem though, if I input 5000 and
500000 I get the same result (50) because you don't tell the user the
type of the answer.

Also notice that the variable result_of_formula is never used so you can
delete it. You can also, if you wish, get rid of the variables
new_currency_value and value_in_pessewas by performing the calculations
in the if-statement, like this:

#include <iostream>
using namespace std;

int main() {
double old;

cout << "Please enter the value of the old currency"
"you wish to convert" << endl;
cin >old;

if (old < 10000) {
cout << "The value of the new currency is "
<< old / 100 << " pessewas" << endl;
}
else {
cout << "The value if the new currency is "
<< old / 10000 << " cedi" << endl;
}
return 0;

}

--
Erik Wikström
Many thanks Erik
You have given me valuable information. I guess you're right with the
50 result. I need to specify which denomination -cedis or pessewas-
i'm talking about. True. I'll rewrite the code and make the
modifications you have suggested. Thank you very much indeed. Any more
suggestions for this small program are welcome.

Jul 3 '07 #11
On Jul 3, 2:00 pm, mereba <jojoo.imb...@gmail.comwrote:
On Jul 3, 5:11 pm, Erik Wikström <Erik-wikst...@telia.comwrote:


On 2007-07-03 17:23, mereba wrote:
On Jul 3, 1:35 pm, "Daniel T." <danie...@earthlink.netwrote:
>mereba <jojoo.imb...@gmail.comwrote:
My country Ghana is changing its currency. I want to write a small
programme in C++ that can covert from the old currency into the new
one. I would like this programme to run behind a simple calculator-
looking interface. I'm quite new to C++, and I would need some help.
Please any suggestion is welcome :)
>Frankly, it sounds like homework. Google, "Ghana currency converter"and
>you will find dozens of them.
The following is what I have been able to do so far:
#include <iostream>
using namespace std;
int main(){
//variables declared
int old_currency_value, new_currency_value, result_of_formula;
//questions to ask user
cout<< "Please enter the value of the old currency you wish to
convert";
cin >old_currency_value;
//conversion implementation
new_currency_value = old_currency_value/10000;
cout << "The value of the new currency is " << new_currency_value <<
endl;
//quit programme
return 0;
>Your missing the close paren at the end, otherwise your program will
>compile and run. Is the output what you expected?
This is no joke Daniel T :).My country is CHANGING its currency. I'm
not looking for some fancy converters from the old Ghana cedi to US
dollars and other currencies. I'm looking to write my own programme
that can convert from the old Ghana cedi to the NEW Ghana cedi, and I
intend to do just that with C++. Thanks for the tip about closing
parentheses. It is well noted. Please more suggestions are welcome.
The source code now looks like this:
Looks quite good, there is one problem though, if I input 5000 and
500000 I get the same result (50) because you don't tell the user the
type of the answer.
Also notice that the variable result_of_formula is never used so you can
delete it. You can also, if you wish, get rid of the variables
new_currency_value and value_in_pessewas by performing the calculations
in the if-statement, like this:
#include <iostream>
using namespace std;
int main() {
double old;
cout << "Please enter the value of the old currency"
"you wish to convert" << endl;
cin >old;
if (old < 10000) {
cout << "The value of the new currency is "
<< old / 100 << " pessewas" << endl;
}
else {
cout << "The value if the new currency is "
<< old / 10000 << " cedi" << endl;
}
return 0;
}
--
Erik Wikström

Many thanks Erik
You have given me valuable information. I guess you're right with the
50 result. I need to specify which denomination -cedis or pessewas-
i'm talking about. True. I'll rewrite the code and make the
modifications you have suggested. Thank you very much indeed. Any more
suggestions for this small program are welcome.- Hide quoted text -

- Show quoted text -
It would be niec if you could specify command line options. That way
no user input is really needed. From your post it looks like either
the old or new currency is called "cedis" and the other one is called
"pessewas". So, wouldn't it be niec if you could type something like
this?

$convert 1000p
1000 pessewas is 4705 cedis

$convert 1000c
1000 cedis is 200 pessewas
The following inputs might be nice also

$convert
Enter the amount to convert: 1000c
1000 cedis is 200 pessewas

$convert
Enter the amount to convert: 1000
1000 pessewas or cedis? p
1000 pessewas is 4705 cedis
To read command line arguments, you will need to first declare main
function differently:

int main(int argc, char** argv)
{
}

Then, use argc and argv parameters to the main function. argc = 1 if
no additional parameters are specified on the command line (because
"convert" is always the first parameter) 2 if one additional
parameters are specified, etc). argv is an array of command line
parameters. So, for example say you run the program like this:

$convert 1000p

Then, argc=2 and argv = { "convert", "1000p" }

Good luck.

Jul 3 '07 #12
On Jul 3, 7:00 pm, mereba <jojoo.imb...@gmail.comwrote:
On Jul 3, 5:11 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-07-03 17:23, mereba wrote:
On Jul 3, 1:35 pm, "Daniel T." <danie...@earthlink.netwrote:
>mereba <jojoo.imb...@gmail.comwrote:
My country Ghana is changing its currency. I want to write a small
programme in C++ that can covert from the old currency into the new
one. I would like this programme to run behind a simple calculator-
looking interface. I'm quite new to C++, and I would need some help.
Please any suggestion is welcome :)
>Frankly, it sounds like homework. Google, "Ghana currency converter"and
>you will find dozens of them.
The following is what I have been able to do so far:
#include <iostream>
using namespace std;
int main(){
//variables declared
int old_currency_value, new_currency_value, result_of_formula;
//questions to ask user
cout<< "Please enter the value of the old currency you wish to
convert";
cin >old_currency_value;
//conversion implementation
new_currency_value = old_currency_value/10000;
cout << "The value of the new currency is " << new_currency_value <<
endl;
//quit programme
return 0;
>Your missing the close paren at the end, otherwise your program will
>compile and run. Is the output what you expected?
This is no joke Daniel T :).My country is CHANGING its currency. I'm
not looking for some fancy converters from the old Ghana cedi to US
dollars and other currencies. I'm looking to write my own programme
that can convert from the old Ghana cedi to the NEW Ghana cedi, and I
intend to do just that with C++. Thanks for the tip about closing
parentheses. It is well noted. Please more suggestions are welcome.
The source code now looks like this:
Looks quite good, there is one problem though, if I input 5000 and
500000 I get the same result (50) because you don't tell the user the
type of the answer.
Also notice that the variable result_of_formula is never used so you can
delete it. You can also, if you wish, get rid of the variables
new_currency_value and value_in_pessewas by performing the calculations
in the if-statement, like this:
#include <iostream>
using namespace std;
int main() {
double old;
cout << "Please enter the value of the old currency"
"you wish to convert" << endl;
cin >old;
if (old < 10000) {
cout << "The value of the new currency is "
<< old / 100 << " pessewas" << endl;
}
else {
cout << "The value if the new currency is "
<< old / 10000 << " cedi" << endl;
}
return 0;
}
--
Erik Wikström

Many thanks Erik
You have given me valuable information. I guess you're right with the
50 result. I need to specify which denomination -cedis or pessewas-
i'm talking about. True. I'll rewrite the code and make the
modifications you have suggested. Thank you very much indeed. Any more
suggestions for this small program are welcome.
OK. I just compiled and run Erik's rewrite, and it works perfectly. I
guess I'm now left to figure out how to write a GUI for this small
program. Earlier posters have advised that I should join other forums
for topics about GUIs. However, I would very much like for the people
who pointed me to all the right directions to suggest GUI tools that I
should try out and select. I would want to be able to let this program
run on both windows and linux systems.
Many thanks!

Jul 3 '07 #13
On Jul 3, 7:09 pm, Zachary Turner <divisorthe...@gmail.comwrote:
On Jul 3, 2:00 pm, mereba <jojoo.imb...@gmail.comwrote:
On Jul 3, 5:11 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-07-03 17:23, mereba wrote:
On Jul 3, 1:35 pm, "Daniel T." <danie...@earthlink.netwrote:
mereba <jojoo.imb...@gmail.comwrote:
My country Ghana is changing its currency. I want to write a small
programme in C++ that can covert from the old currency into the new
one. I would like this programme to run behind a simple calculator-
looking interface. I'm quite new to C++, and I would need some help.
Please any suggestion is welcome :)
Frankly, it sounds like homework. Google, "Ghana currency converter" and
you will find dozens of them.
The following is what I have been able to do so far:
#include <iostream>
using namespace std;
int main(){
//variables declared
int old_currency_value, new_currency_value, result_of_formula;
//questions to ask user
cout<< "Please enter the value of the old currency you wish to
convert";
cin >old_currency_value;
//conversion implementation
new_currency_value = old_currency_value/10000;
cout << "The value of the new currency is " << new_currency_value <<
endl;
//quit programme
return 0;
Your missing the close paren at the end, otherwise your program will
compile and run. Is the output what you expected?
This is no joke Daniel T :).My country is CHANGING its currency. I'm
not looking for some fancy converters from the old Ghana cedi to US
dollars and other currencies. I'm looking to write my own programme
that can convert from the old Ghana cedi to the NEW Ghana cedi, andI
intend to do just that with C++. Thanks for the tip about closing
parentheses. It is well noted. Please more suggestions are welcome.
The source code now looks like this:
Looks quite good, there is one problem though, if I input 5000 and
500000 I get the same result (50) because you don't tell the user the
type of the answer.
Also notice that the variable result_of_formula is never used so you can
delete it. You can also, if you wish, get rid of the variables
new_currency_value and value_in_pessewas by performing the calculations
in the if-statement, like this:
#include <iostream>
using namespace std;
int main() {
double old;
cout << "Please enter the value of the old currency"
"you wish to convert" << endl;
cin >old;
if (old < 10000) {
cout << "The value of the new currency is "
<< old / 100 << " pessewas" << endl;
}
else {
cout << "The value if the new currency is "
<< old / 10000 << " cedi" << endl;
}
return 0;
}
--
Erik Wikström
Many thanks Erik
You have given me valuable information. I guess you're right with the
50 result. I need to specify which denomination -cedis or pessewas-
i'm talking about. True. I'll rewrite the code and make the
modifications you have suggested. Thank you very much indeed. Any more
suggestions for this small program are welcome.- Hide quoted text -
- Show quoted text -

It would be niec if you could specify command line options. That way
no user input is really needed. From your post it looks like either
the old or new currency is called "cedis" and the other one is called
"pessewas". So, wouldn't it be niec if you could type something like
this?

$convert 1000p
1000 pessewas is 4705 cedis

$convert 1000c
1000 cedis is 200 pessewas

The following inputs might be nice also

$convert
Enter the amount to convert: 1000c
1000 cedis is 200 pessewas

$convert
Enter the amount to convert: 1000
1000 pessewas or cedis? p
1000 pessewas is 4705 cedis

To read command line arguments, you will need to first declare main
function differently:

int main(int argc, char** argv)
{

}

Then, use argc and argv parameters to the main function. argc = 1 if
no additional parameters are specified on the command line (because
"convert" is always the first parameter) 2 if one additional
parameters are specified, etc). argv is an array of command line
parameters. So, for example say you run the program like this:

$convert 1000p

Then, argc=2 and argv = { "convert", "1000p" }

Good luck.
Thank you very much Zachary Turner. I'm going to incorporate command
line into my programme. But I want to ask - will the command line
options give me more trouble when I'm designing a GUI for this small
programme?

Jul 3 '07 #14
On Jul 3, 7:09 pm, Zachary Turner <divisorthe...@gmail.comwrote:
On Jul 3, 2:00 pm, mereba <jojoo.imb...@gmail.comwrote:
On Jul 3, 5:11 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-07-03 17:23, mereba wrote:
On Jul 3, 1:35 pm, "Daniel T." <danie...@earthlink.netwrote:
mereba <jojoo.imb...@gmail.comwrote:
My country Ghana is changing its currency. I want to write a small
programme in C++ that can covert from the old currency into the new
one. I would like this programme to run behind a simple calculator-
looking interface. I'm quite new to C++, and I would need some help.
Please any suggestion is welcome :)
Frankly, it sounds like homework. Google, "Ghana currency converter" and
you will find dozens of them.
The following is what I have been able to do so far:
#include <iostream>
using namespace std;
int main(){
//variables declared
int old_currency_value, new_currency_value, result_of_formula;
//questions to ask user
cout<< "Please enter the value of the old currency you wish to
convert";
cin >old_currency_value;
//conversion implementation
new_currency_value = old_currency_value/10000;
cout << "The value of the new currency is " << new_currency_value <<
endl;
//quit programme
return 0;
Your missing the close paren at the end, otherwise your program will
compile and run. Is the output what you expected?
This is no joke Daniel T :).My country is CHANGING its currency. I'm
not looking for some fancy converters from the old Ghana cedi to US
dollars and other currencies. I'm looking to write my own programme
that can convert from the old Ghana cedi to the NEW Ghana cedi, andI
intend to do just that with C++. Thanks for the tip about closing
parentheses. It is well noted. Please more suggestions are welcome.
The source code now looks like this:
Looks quite good, there is one problem though, if I input 5000 and
500000 I get the same result (50) because you don't tell the user the
type of the answer.
Also notice that the variable result_of_formula is never used so you can
delete it. You can also, if you wish, get rid of the variables
new_currency_value and value_in_pessewas by performing the calculations
in the if-statement, like this:
#include <iostream>
using namespace std;
int main() {
double old;
cout << "Please enter the value of the old currency"
"you wish to convert" << endl;
cin >old;
if (old < 10000) {
cout << "The value of the new currency is "
<< old / 100 << " pessewas" << endl;
}
else {
cout << "The value if the new currency is "
<< old / 10000 << " cedi" << endl;
}
return 0;
}
--
Erik Wikström
Many thanks Erik
You have given me valuable information. I guess you're right with the
50 result. I need to specify which denomination -cedis or pessewas-
i'm talking about. True. I'll rewrite the code and make the
modifications you have suggested. Thank you very much indeed. Any more
suggestions for this small program are welcome.- Hide quoted text -
- Show quoted text -

It would be niec if you could specify command line options. That way
no user input is really needed. From your post it looks like either
the old or new currency is called "cedis" and the other one is called
"pessewas". So, wouldn't it be niec if you could type something like
this?

$convert 1000p
1000 pessewas is 4705 cedis

$convert 1000c
1000 cedis is 200 pessewas

The following inputs might be nice also

$convert
Enter the amount to convert: 1000c
1000 cedis is 200 pessewas

$convert
Enter the amount to convert: 1000
1000 pessewas or cedis? p
1000 pessewas is 4705 cedis

To read command line arguments, you will need to first declare main
function differently:

int main(int argc, char** argv)
{

}

Then, use argc and argv parameters to the main function. argc = 1 if
no additional parameters are specified on the command line (because
"convert" is always the first parameter) 2 if one additional
parameters are specified, etc). argv is an array of command line
parameters. So, for example say you run the program like this:

$convert 1000p

Then, argc=2 and argv = { "convert", "1000p" }

Good luck.
Zachary, is this the right way for me to include the command line
options?

int main(int argc, char** argv) {

argc=2;
argv = { "convert", "1000p" };

return 0;
}

Jul 3 '07 #15
mereba <jo**********@gmail.comwrote:
OK. I just compiled and run Erik's rewrite, and it works perfectly. I
guess I'm now left to figure out how to write a GUI for this small
program. Earlier posters have advised that I should join other forums
for topics about GUIs. However, I would very much like for the people
who pointed me to all the right directions to suggest GUI tools that I
should try out and select. I would want to be able to let this program
run on both windows and linux systems.
Someone suggested that you try QT. Another option for a GUI is
wxWidgets, which also runs on both Windows and Linux:

http://www.wxwidgets.org/

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Jul 3 '07 #16
mereba <jo**********@gmail.comwrote:
Zachary, is this the right way for me to include the command line
options?

int main(int argc, char** argv) {

argc=2;
argv = { "convert", "1000p" };

return 0;
}
I'm not Zacharay, but here is a very basic example of command line
option usage:
#include <iostream>

int main(int argc, char* argv[])
{
using std::cout;

cout << "argc = " << argc << '\n';

for (int i = 0; i != argc; ++i) {
cout << "argv[" << i << "] = " << argv[i] << '\n';
}

return 0;
}

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Jul 3 '07 #17
On Jul 3, 9:00 pm, ricec...@gehennom.invalid (Marcus Kwok) wrote:
mereba <jojoo.imb...@gmail.comwrote:
Zachary, is this the right way for me to include the command line
options?
int main(int argc, char** argv) {
argc=2;
argv = { "convert", "1000p" };
return 0;
}

I'm not Zacharay, but here is a very basic example of command line
option usage:

#include <iostream>

int main(int argc, char* argv[])
{
using std::cout;

cout << "argc = " << argc << '\n';

for (int i = 0; i != argc; ++i) {
cout << "argv[" << i << "] = " << argv[i] << '\n';
}

return 0;

}

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Thank you Marcus Kwok for the wxWidgets link.
However, I'm confused about the command line options programme. What
does it do? Really I would like to know. I run your programme and this
is the output I got:

argc = 1
argv[0] = ./commandline

I guess "./commandline" without the quotes is showing up because I
named the object file commandline? Please explain further

Jul 3 '07 #18
On Jul 3, 7:00 pm, mereba <jojoo.imb...@gmail.comwrote:
On Jul 3, 5:11 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-07-03 17:23, mereba wrote:
On Jul 3, 1:35 pm, "Daniel T." <danie...@earthlink.netwrote:
>mereba <jojoo.imb...@gmail.comwrote:
My country Ghana is changing its currency. I want to write a small
programme in C++ that can covert from the old currency into the new
one. I would like this programme to run behind a simple calculator-
looking interface. I'm quite new to C++, and I would need some help.
Please any suggestion is welcome :)
>Frankly, it sounds like homework. Google, "Ghana currency converter"and
>you will find dozens of them.
The following is what I have been able to do so far:
#include <iostream>
using namespace std;
int main(){
//variables declared
int old_currency_value, new_currency_value, result_of_formula;
//questions to ask user
cout<< "Please enter the value of the old currency you wish to
convert";
cin >old_currency_value;
//conversion implementation
new_currency_value = old_currency_value/10000;
cout << "The value of the new currency is " << new_currency_value <<
endl;
//quit programme
return 0;
>Your missing the close paren at the end, otherwise your program will
>compile and run. Is the output what you expected?
This is no joke Daniel T :).My country is CHANGING its currency. I'm
not looking for some fancy converters from the old Ghana cedi to US
dollars and other currencies. I'm looking to write my own programme
that can convert from the old Ghana cedi to the NEW Ghana cedi, and I
intend to do just that with C++. Thanks for the tip about closing
parentheses. It is well noted. Please more suggestions are welcome.
The source code now looks like this:
Looks quite good, there is one problem though, if I input 5000 and
500000 I get the same result (50) because you don't tell the user the
type of the answer.
Also notice that the variable result_of_formula is never used so you can
delete it. You can also, if you wish, get rid of the variables
new_currency_value and value_in_pessewas by performing the calculations
in the if-statement, like this:
#include <iostream>
using namespace std;
int main() {
double old;
cout << "Please enter the value of the old currency"
"you wish to convert" << endl;
cin >old;
if (old < 10000) {
cout << "The value of the new currency is "
<< old / 100 << " pessewas" << endl;
}
else {
cout << "The value if the new currency is "
<< old / 10000 << " cedi" << endl;
}
return 0;
}
--
Erik Wikström

Many thanks Erik
You have given me valuable information. I guess you're right with the
50 result. I need to specify which denomination -cedis or pessewas-
i'm talking about. True. I'll rewrite the code and make the
modifications you have suggested. Thank you very much indeed. Any more
suggestions for this small program are welcome.
OK. So I have been able to make the modifications. This is the new
writeup:

#include <iostream>
using namespace std;

int main(){
int old_cedi, old_cedi_part;
double pessewa;

cout << "Please enter the value of the old currency"
<< " you wish to convert" << endl;
cin >old_cedi;

if (old_cedi < 10000){
cout << "The value of the new currency is Gp"
<< old_cedi / 100 << endl;
}

else{
old_cedi_part = old_cedi / 10000;
pessewa = (old_cedi -(old_cedi_part * 10000))/100;
cout << "The value of the new currency is GHC"
<< old_cedi_part << " and Gp" << pessewa;
}
return 0;
}

Jul 3 '07 #19
On Jul 3, 12:58 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
"mereba" <jojoo.imb...@gmail.comwrote in message
news:11**********************@m36g2000hse.googlegr oups.com...
On Jul 3, 10:30 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
"mereba" <jojoo.imb...@gmail.comwrote in message
news:11**********************@m36g2000hse.googleg roups.com...
1. How do I write a gui in C++ for this programme?
GUI is beyond the scope of this newsgroup, it is platform dependant.
It's not necessarily platform dependant: wxWidgets, for example,
can be used pretty much everywhere. (Well, pretty much
everywhere that supports windowing. I doubt that it could be
ported to a PDP-11 with a teletype.)

More to the point, perhaps, is that GUI programming is at least
as complicated as C++. A question like "how do I write a GUI?"
is about as answerable as "how do I write a program in C++?".
There's a trivial but useless answer: use a text editor, but
anything useful would go well beyond the scope of a news
article. And while I think that the original charter does allow
for questions concerning portable libraries, like wxWidgets,
realistically, it's a language within a language, and everyone
(including the person with the question) is better off if the
question is asked in a dedicated group, like
comp.soft-sys.wxwidgets. But even there, only after having read
a good introductory tutorial, read the FAQ, etc., etc.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 4 '07 #20
On Jul 4, 9:59 am, James Kanze <james.ka...@gmail.comwrote:
On Jul 3, 12:58 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
"mereba" <jojoo.imb...@gmail.comwrote in message
news:11**********************@m36g2000hse.googlegr oups.com...
On Jul 3, 10:30 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
>"mereba" <jojoo.imb...@gmail.comwrote in message
>>news:11**********************@m36g2000hse.google groups.com...
1. How do I write a gui in C++ for this programme?
GUI is beyond the scope of this newsgroup, it is platform dependant.

It's not necessarily platform dependant: wxWidgets, for example,
can be used pretty much everywhere. (Well, pretty much
everywhere that supports windowing. I doubt that it could be
ported to a PDP-11 with a teletype.)

More to the point, perhaps, is that GUI programming is at least
as complicated as C++. A question like "how do I write a GUI?"
is about as answerable as "how do I write a program in C++?".
There's a trivial but useless answer: use a text editor, but
anything useful would go well beyond the scope of a news
article. And while I think that the original charter does allow
for questions concerning portable libraries, like wxWidgets,
realistically, it's a language within a language, and everyone
(including the person with the question) is better off if the
question is asked in a dedicated group, like
comp.soft-sys.wxwidgets. But even there, only after having read
a good introductory tutorial, read the FAQ, etc., etc.

--
James Kanze (GABI Software) email:james.ka...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Thank you for your suggestion James. I have started with a wxwidgets
tutorial. Thank you all for the good suggestions you all have given me.

Jul 4 '07 #21

mereba <jo**********@gmail.comwrote in message...
>
Thank you Marcus Kwok for the wxWidgets link.
However, I'm confused about the command line options programme. What
does it do? Really I would like to know. I run your programme and this
is the output I got:

argc = 1
argv[0] = ./commandline

I guess "./commandline" without the quotes is showing up because I
named the object file commandline? Please explain further
Usually the first argv is the program being invoked. On windows, we usually
get the full pathname, 'D:\MyStuff\MyProgram'.

Try starting your program with some commandline arguments:

./commandline -aflag -aparm "my line of input"

What do you get for output now?

--
Bob R
POVrookie
Jul 4 '07 #22
On Jul 4, 4:01 pm, "BobR" <removeBadB...@worldnet.att.netwrote:
mereba <jojoo.imb...@gmail.comwrote in message...
Thank you Marcus Kwok for the wxWidgets link.
However, I'm confused about the command line options programme. What
does it do? Really I would like to know. I run your programme and this
is the output I got:
argc = 1
argv[0] = ./commandline
I guess "./commandline" without the quotes is showing up because I
named the object file commandline? Please explain further

Usually the first argv is the program being invoked. On windows, we usually
get the full pathname, 'D:\MyStuff\MyProgram'.

Try starting your program with some commandline arguments:

./commandline -aflag -aparm "my line of input"

What do you get for output now?

--
Bob R
POVrookie
Bob R, I literally inserted "my line of input", and when I ran the
programme, this is the output I got:

argc = 4
argv[0] = ./commandline
argv[1] = -aflag
argv[2] = -aparm
argv[3] = my line of input

It doesn't appear to me that argv is doing anything fancy here -
storing strings into an array, of course according to what commandline
has been compiled to do. Is there more to this than meets the eye?

Jul 4 '07 #23

James Kanze <ja*********@gmail.comwrote in message...
/* """
(I'm not trying to criticize your answer here. I know you gave
a simple answer to someone who is pretty much a beginner, not
wanting to confuse him with details. But I'm honestly curious;
I know that the behavior under Unix is in fact fairly complex,
although most users can ignore the complexity most of the time,
and I'm curious as to the details under Windows.)
""" */

Well, without throwing any more brain-dead ideas at you, maybe see Ralf
Browns list (is that puppy still around? :-} ).
Under DOS/Assembler we were assured to get a specific set of data, relative
to the address the program was loaded to. Under 'vista', 'ntfs', 'Reiserfs
(sp?)', etc., well I just don't know.
Every OS/filesystem seems to 'do it their way' (F.Sinatra). <G>
[ I guess it's a little late to ask for a standardization of the 'comand
line' args?
<G(oops, there's that brain-dead' now) ]
This is from some *old* docs I have, GCC libC, "Program Arguments":
"
The value of the argc argument is the number of command line arguments. The
argv argument is a vector of C strings; its elements are the individual
command line argument strings.
** The file name of the program being run is also included in the vector as
the first element; the value of argc counts this element. **
A null pointer always follows the last element: argv[argc] is this null
pointer.
// .... later...
In Unix systems you can define main a third way, using three arguments:
int main (int argc, char *argv[], char *envp[])
"
Newer docs may have some amendments.

I know under wxWidgets(wxMSW, wxGTK,(others?)), the 'argc/argv' are provided
(but I have not examined their methods).

--
Bob R
POVrookie
Jul 4 '07 #24

mereba <jo**********@gmail.comwrote in message...
On Jul 4, 4:01 pm, "BobR" <removeBadB...@worldnet.att.netwrote:
Try starting your program with some commandline arguments:

./commandline -aflag -aparm "my line of input"

What do you get for output now?

Bob R, I literally inserted "my line of input", and when I ran the
programme, this is the output I got:

argc = 4
argv[0] = ./commandline
argv[1] = -aflag
argv[2] = -aparm
argv[3] = my line of input

It doesn't appear to me that argv is doing anything fancy here -
storing strings into an array, of course according to what commandline
has been compiled to do. Is there more to this than meets the eye?
Next step, do something with the input.

#include <iostream>
#include <string>

int main(int argc, char* argv[]){
using std::cout;
cout << "argc = " << argc << '\n';
for (int i = 0; i != argc; ++i) {
cout << "argv[" << i << "] = " << argv[i] << '\n';

std::string arg( argv[i] );
if( arg.find("-aparm") != arg.npos ){
cout<<"\"-aparm\" found."<<'\n';
// - do stuff here -
}
if( arg.find("-aflag") != arg.npos ){
cout<<"\"-aflag\" found."<<'\n';
// - do stuff here -
}
// etc.
}

return 0;
}

There are different ways, but, I don't want to confuse you. Take it in small
steps. Do you know std::vector?

--
Bob R
POVrookie
Jul 5 '07 #25
On Jul 5, 4:40 am, "BobR" <removeBadB...@worldnet.att.netwrote:
mereba <jojoo.imb...@gmail.comwrote in message...
On Jul 4, 4:01 pm, "BobR" <removeBadB...@worldnet.att.netwrote:
Try starting your program with some commandline arguments:
./commandline -aflag -aparm "my line of input"
What do you get for output now?
Bob R, I literally inserted "my line of input", and when I ran the
programme, this is the output I got:
argc = 4
argv[0] = ./commandline
argv[1] = -aflag
argv[2] = -aparm
argv[3] = my line of input
It doesn't appear to me that argv is doing anything fancy here -
storing strings into an array, of course according to what commandline
has been compiled to do. Is there more to this than meets the eye?

Next step, do something with the input.

#include <iostream>
#include <string>

int main(int argc, char* argv[]){
using std::cout;
cout << "argc = " << argc << '\n';
for (int i = 0; i != argc; ++i) {
cout << "argv[" << i << "] = " << argv[i] << '\n';

std::string arg( argv[i] );
if( arg.find("-aparm") != arg.npos ){
cout<<"\"-aparm\" found."<<'\n';
// - do stuff here -
}
if( arg.find("-aflag") != arg.npos ){
cout<<"\"-aflag\" found."<<'\n';
// - do stuff here -
}
// etc.
}

return 0;
}

There are different ways, but, I don't want to confuse you. Take it in small
steps. Do you know std::vector?

--
Bob R
POVrookie
Thanks Bob R for your efforts. I'll play around with the code, and try
to grasp the argc and argv[] parameter concepts.

No. I don't yet know std::vector. I've googled around a little for it,
and so far all I know is that it is a standard header (#include
<vector>). I'm yet to understand it a little better. Please post links
that can help my understanding.

Jul 5 '07 #26

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Philip D Heady | last post by:
Anyone know where i can find all world currencies (USD,etc) and do an import into mySQL? Just need a comma delimited list if possible. Example: USD, United States Dollar etc, etc
2
by: techy techno | last post by:
hii Experts..!! I need someone to tell me where I can get a Currency Converter like http://cconv.textor.com please can someone tell me where I can get it I need it for free + I dont need...
7
by: meenasamy | last post by:
Hi all, i need to create a function that takes three parameters( Original currency, needed currency, amount) i need to convert from the original currency to the needed currency the amount and...
2
by: Rash33d | last post by:
Hi there! could som1 please help me out? i need toknow if there's something wrong with this javascript code. The code is meant to give the american dollar and european equivalent of a price. i.e...
10
by: jayender.vs | last post by:
Hello guys, I need to know the Currency conversion code in Javascript Say for example i got 2 textbox .. where i enter a number (singapore doller value) and i provide a button and in the next text...
2
by: Raj | last post by:
Is there a current converter web service available? Currency rates are to be as per latest exchange rates. Raj.
12
AdrianH
by: AdrianH | last post by:
Does anyone know where I can get a PHP currency converter? Adrian
7
by: tararreb | last post by:
#include<stdio.h> /*This line is standard input output, # is directive, include is keyword, and stdio.h is header file*/ #include<stdlib.h> /*This line is standard input output, # is directive,...
1
by: katie20 | last post by:
Hi everyone, I have written a code in order to produce a currency converter. My program will be designed to convert pounds into euros using visual basic programming. I have two text boxes and one...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.