-
Some Help Needed!
I have written code to convert foreign currency into US dollars. Now I am trying to write code for a menu (display using loop) that allows the user to choose which currency and the amount of the foreign currency they wish to convert to US dollars. I am using Function(s) must be used. Below is what I have so far!
#include<iostream.h>
double amount = 0.0; /*Stores user input*/
int main()
{
cout<<"Currency Conversion"<<endl;
cout<<"--------------------\n";
cout<<"Enter the amount in US Dollar: "; /*Prompt user for amount*/
cin>>amount; /* Read in the amount*/
/*Convert the amount to each currency type and print it out*/
cout<<amount<<" US Dollars = "<<amount/0.6072<<" Swiss Francs\n";
cout<<amount<<" US Dollars = "<<amount/1.4320<<" British Pounds\n";
cout<<amount<<" US Dollars = "<<amount/0.0081<<" Japanese Yens\n";
cout<<amount<<" US Dollars = "<<amount/0.6556<<" Canadian Dollars\n";
cout<<amount<<" US Dollars = "<<amount/0.8923<<" Euros\n";
}
:confused:
-
Use void commands...
Code:
#include <iostream.h>
#include <conio.h>
void menu();
void US2YEN();
float amount;
int choice;
int main()
{
cout<<"Welcome to my converter!"<<endl;
cin.get();
menu(); //after enter is hit go to menu func.
return 0;
}
void menu()
{
cout << " Menu"<<endl;
cout << "_________"<<endl<<endl;
cout << " 1) Us to Yen"<<endl<<endl;
cout << "Make your choice: "; cin >>choice;
if( choice == 1) US2YEN();
else{
clrscr();
menu();
}
}
void US2YEN()
{
// CODE HERE
}
yah its kinda rough... if you cant understand tell me
-
I am not that good of a coder, but I will try. By the way if this is a school assignment, you are missing out on learning by having other people do it.
Code:
#include <iostream>
#define FRANCS 0.6072
#define POUNDS 1.4320
#define YEN 0.0081
#define CDOLLARS 0.6556
#define EUROS 0.8923
using namespace std;
int menu();
void convertmoney(int amount, double type);
int main()
{
int money;
cout << "How much money to convert? ";
cin >> money;
int menuchoice;
menuchoice = menu();
switch(menuchoice)
{
case 1:
convertmoney(money, FRANCS);
break;
case 2:
convertmoney(money, POUNDS);
break;
case 3:
convertmoney(money, YEN);
break;
case 4:
convertmoney(money, CDOLLARS);
break;
case 5:
convertmoney(money, EUROS);
break;
default:
return 0;
break;
}
}
int menu()
{
cout << "Convert to what currency?" << endl;
cout << "[1] - Swiss Francs" << endl;
cout << "[2] - British Pounds" << endl;
cout << "[3] - Japanese Yen" << endl;
cout << "[4] - Canadian Dollars" << endl;
cout << "[5] - Euros" << endl;
int temp;
cin >> temp;
return temp;
}
void convertmoney(int amount, double type)
{
cout << "The amount is " << amount/type << endl;
}
-
And so it came to pass another student got his homework done for him :rolleyes:
-
I really appreciate your help!
-
Oh well, when he gets a test in class he will fail. Or when his teacher ask him how the code works. He only hurts himself by asking, and I like coding little stuff.
-
Ahhh... Then your code may be interpreted as a form of punishment? Excellent! I was afraid for a brief moment that our little pest was being rewarded for ignoring virtually every guideline this forum has.
(I think I hear a collective pounding of heads on the table. Easy, Mario!!)
;)
-
LOL!
Dang! Have to switch my webcam off ;)