write small currency converter

M

mereba

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;
 
J

Jim Langston

mereba said:
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?
 
M

mereba

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?
 
J

Jim Langston

mereba said:
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
 
M

mereba

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).


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?
 
I

Ivan Vecerina

: 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?

Hi Mereba,
The problem is, there is no standard GUI programming library
in C++, but a multitude of GUI toolkits and frameworks
that function on various platforms. So no-one can guess
which toolkit you are using, and few people in this C++
newsgroup will be familiar with the one you are asking about.

So you have to ask your question in a forum dedicated to
the platform or to the specific library that you intend
to use.
 
Z

Zeppe

mereba said:
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
 
M

mereba

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.




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.
 
D

Daniel T.

mereba said:
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?
 
M

mereba

Frankly, it sounds like homework. Google, "Ghana currency converter" and
you will find dozens of them.













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;
}
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

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;
}
 
M

mereba

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;

}

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.
 
Z

Zachary Turner

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.
 
M

mereba

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!
 
M

mereba

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?
 
M

mereba

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;
}
 
M

Marcus Kwok

mereba said:
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/
 
M

Marcus Kwok

mereba said:
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 << '\n';
}

return 0;
}
 
M

mereba

mereba said:
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 << '\n';
}

return 0;

}


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
 
M

mereba

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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top