By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,241 Members | 760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,241 IT Pros & Developers. It's quick & easy.

write small currency converter

P: n/a
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
Share this Question
Share on Google+
25 Replies


P: n/a
"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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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

P: n/a

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

P: n/a

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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.