|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
hi i am writing this program in VI using C++ but i am kind blocked and a little confused into main so many syintax too. guys i will apreciate.
thanks here is the orginal prog (problem) Create a menu-driven program that will convert American dollars to a foreign currency. The program should allow the user to enter a number of dollars and select the foreign currency from a list. The program should then display a message like: $300 dollars is 34270.5 Yen. Your program should be able to convert to the following currencies at the given exchange rates: European Euro = 0.691052 Canadian Dollar = 0.933197 Japanese Yen = 114.505 Indian Rupee = 39.18 Swiss Franc = 1.15321 Brazilian Real = 1.754 Chinese Yuan = 7.45507 Icelandic Kronur = 59.2400 Kenyan Shilling = 66.4825 Mexican Pesos = 10.7267 Your program should also have an "Other" catagory in which the user can enter an exchange rate. Your program should employ modular program techniques (functions). Implement input validation. If the number of dollars (or exchange rate when choosing "Other") is negative, or if the currency chosen is not one of the ones listed, display an error and exit the program. this is my ans and how far i got Code:
#include <iostream>
using namespace std;
float dollars;
float euro;
float canadian dollars;
float japanese yen;
float indian rupee;
float swis franc;
float braziallian real;
float chines yuan;
float icelandic kronur;
float kenyan shilling;
float mexican pesos;
char get_currency_type( )
flaot calculate_currency(char type, float convert)
void report currency(char type, float convert)
char get currency_type( ){
char currency;
if (currency == "euro")
extent = "euro"
else if (currency == "canadian")
extent = "canadian"
else if (currency == "rupee")
extent = "rupee"
else if (currency == "franc")
extent = "franc"
else if (currency == "real")
extent = "real"
else if (currency == "yuan")
extent = "yuan"
else if (currency == "kronur")
extent = "kronur"
else if (currency == "shilling")
extent = "shilling"
else if (currency == "pesos")
extent = "pesos"
else return extent;
int main( ){
kind = get_currency_type( )
bill = calculate_currency(kind, bill);
report_currency(kind, bill);
cout << "enter the type of currency";
cin >> currency;
cout << "enter the amount of dollars";
cin >> dollars;
float calculate currency (char type, float conversion)
float conversion
switch(conversion){
case "euro";
conversion = dollars*.691052
break;
case "canadian";
conversion = dollars*.933197
break;
case "rupee";
conversion = dollars*39.18
break;
case "franc";
conversion = dollars*1.15321
break;
case "real";
conversion = dollars*1.754
break;
case "yuan";
conversion = dollars*7.45507
break;
case "kronur";
conversion = dollars*59.2400
break;
case "shilling";
conversion = dollars*66.4825
break;
case "pesos";
conversion = dollars*10.7267
break;
return "conversion";
Last edited by WingedPanther; 11-17-2007 at 09:03 AM. Reason: add code blocks |
| Sponsored Links |
|
|
|
|||
|
i appreciate that, thank you so much
|
|
|||||
|
Just an observation: large chunks of your code are not contained within a function. That will render perfectly good logic useless in a hurry.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Programming is a branch of mathematics. |
| Sponsored Links |
|
|
|
|||
|
I'm sorry to say this, but you have a lot to fix:
1) Some of your variable names and a few function names contain spaces in them. If you must, use an underscore; that's probably why you're getting syntax errors. 2) "float" is misspelled in your calculate_currency() function declaration. 3) You've left out all the semicolons in your function declarations. 4) You declare a local variable currency in your get_currency_type() function (add an underscore there), and then you start comparing it to strings. A) First of all, it's declared as a character, not as a pointer to a character array. You can't do explicit comparisons between strings with the == operator. You'll have to use a library function such as strcmp(), declared in <string.h>. B)Second of all, currency is a local variable, and has no value to begin with. Your function appears to be doing nothing useful - either that, or I'm missing something. Please document your code better. C)Third of all, you never declare the variable extent, so that'll give you more errors. D)Fourth of all, you've left out all semicolons in this function, which is a huge syntax violation. 5)In your main function, you never declare the variables kind or bill - you just use them. You need to declare variables before you use them. Otherwise, the compiler won't know what they are. 6)Again, you seem to have an aversion to semicolons in your calculate_currency() function. The switch statement cannot be used with strings. Also, the semicolons you put after your case statements should be colons. You specify that the function returns a float but then return a string - be consistent! You also left out the closing braces in both the switch statements and the function. I don't mean to be harsh, but I strongly recommend you read a good book about programming in C++ before you go any further. Try writing out the pseudocode first, plan what you're going to do, and then start writing the code. Otherwise you'll end up like me; I modify the code as I go along, and by the time I'm done it's difficult to figure out what does what. Good luck. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |