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; 25 5871
"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?
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?
"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
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?
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
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.
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?
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;
}
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
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.
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.
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!
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?
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;
}
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
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
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
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;
}
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
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.
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
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?
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
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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
|
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...
|
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...
|
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...
|
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...
|
by: Raj |
last post by:
Is there a current converter web service available?
Currency rates are to be as per latest exchange rates.
Raj.
|
by: AdrianH |
last post by:
Does anyone know where I can get a PHP currency converter?
Adrian
|
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,...
|
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...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
| |