GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Sep-2005, 14:12
Pinkyy Pinkyy is offline
New Member
 
Join Date: Sep 2005
Posts: 6
Pinkyy is an unknown quantity at this point

US dollar amount, the result is all zeros.


This is what I basically need. Can someone please help me? I'm lost.

Write a C program that displays a title, "Currency Conversion," and then display the names of five currencies and their equivalents to $100 US dollars. The program must use named constants (for any value that remains constant), variables and equations. The program should calculate the equivalency of $100 US dollars to the Euro, Japanese Yen, UK Pound, Germany Deutsche Marc, French Franc. For purposes of this exercise, use the following conversion factors:

1 US dollar = 0.926698 Euro
1 US dollar = 6.07874 Franc
1 US dollar = 120.300 Yen
1 US dollar = 1.81246 Deutsche Marc
1 US dollar = 0.619579 Pound

Once you have calculated the equivalency of $100 US dollars for each currency (using equations with variables and named constants), display the results on the screen. Be sure to label each result with the correct currency name. Before you display the 5 results, you should display "$100 US dollars is equivalent to:".

I also need the source code for this program. Thanks in advance to anyone that can help me. This is what I have so far.

CPP / C++ / C Code:
#include <stdio.h> 
 
 #define EURO_DOLLAR_FACTOR 0.926698 
 #define FRANC_DOLLAR_FACTOR 6.07874 
 #define MARC_DOLLAR_FACTOR 1.81246 
 #define POUND_DOLLAR_FACTOR 0.619579 
 #define YEN_DOLLAR_FACTOR 120.300 
 #define US_DOLLAR_VALUE 100.00 
 
 float ConvertCurrency(float Factor, float Dollars); 
 
 void main() 
 { 
     
     
     printf("\t\t\t\t Currency Conversion\n"); 
     
     printf("\n\nEnter your first name..."); 
     getch();    
          
     printf("\n"); 
     
     printf("100 US dollars are equal to %f euros\n", 
 ConvertCurrency(EURO_DOLLAR_FACTOR,US_DOLLAR_VALUE)); 
     printf("100 US dollars are equal to %f francs\n", 
 ConvertCurrency(FRANC_DOLLAR_FACTOR,US_DOLLAR_VALUE)); 
     printf("100 US dollars are equal to %f marcs\n", 
 ConvertCurrency(MARC_DOLLAR_FACTOR,US_DOLLAR_VALUE)); 
     printf("100 US dollars are equal to %f pounds\n", 
 ConvertCurrency(POUND_DOLLAR_FACTOR,US_DOLLAR_VALUE)); 
     printf("100 US dollars are equal to %f yens\n", 
 ConvertCurrency(YEN_DOLLAR_FACTOR,US_DOLLAR_VALUE)); 
     /************************************************* 
      * Prompt user to press ENTER key to end program * 
      *************************************************/ 
     printf("\n\nPress Enter key to end..."); 
     getch(); 
 } 
 
 // 
 // Function ConvertCurrency returns the value of Factor times Dollars 
 // 
 float ConvertCurrency(float Factor, float Dollars) 
 { 
     float Result = 0.0; 
 
     Result = Factor * Dollars; 
     return(Result); 
 }
Last edited by admin : 08-Sep-2005 at 20:49. Reason: Please insert your C code between [c] & [/c] tags
  #2  
Old 08-Sep-2005, 14:25
kobi_hikri's Avatar
kobi_hikri kobi_hikri is offline
Regular Member
 
Join Date: Apr 2005
Location: Israel
Posts: 431
kobi_hikri has a spectacular aura aboutkobi_hikri has a spectacular aura about
Where are you lost ?
What is the problem ? I can see that the application is almost finished.
What errors are you getting ?

Kobi Hikri.
  #3  
Old 08-Sep-2005, 14:42
kobi_hikri's Avatar
kobi_hikri kobi_hikri is offline
Regular Member
 
Join Date: Apr 2005
Location: Israel
Posts: 431
kobi_hikri has a spectacular aura aboutkobi_hikri has a spectacular aura about
Quote:
Originally Posted by Pinkyy
This is what I basically need. Can someone please help me? I'm lost.

1. Well, for starters, Your function ConvertCurrency is good, and I didn't change it.
2. I did some indentation and removed your
CPP / C++ / C Code:
getch();
calls as I don't understand their purpose.
3. Why do you ask for student name but dont read it (e.g with scanf) ?
4. You had some errors in places where you wrote your constant names (syntax errors), This is something you shoud get used to check.

Basically a good work :-P

This is the code (your code) I fixed. Try to continue on your own.
Post any problem.

CPP / C++ / C Code:

#include <stdio.h> 

#define EURO_DOLLAR_FACTOR		0.926698 
#define FRANC_DOLLAR_FACTOR		6.07874 
#define MARC_DOLLAR_FACTOR		1.81246 
#define POUND_DOLLAR_FACTOR		0.619579 
#define YEN_DOLLAR_FACTOR		120.300 
#define US_DOLLAR_VALUE			100.00 

float ConvertCurrency(float Factor, float Dollars); 

void main() 
{ 

	printf("\t\t\t\t Currency Conversion\n"); 
	printf("\n"); 

	printf("100 US dollars are equal to %f euros\n", 
	ConvertCurrency(EURO_DOLLAR_FACTOR,US_DOLLAR_VALUE )); 
	printf("100 US dollars are equal to %f francs\n", 
	ConvertCurrency(FRANC_DOLLAR_FACTOR,US_DOLLAR_VALUE)); 
	printf("100 US dollars are equal to %f marcs\n", 
	ConvertCurrency(MARC_DOLLAR_FACTOR,US_DOLLAR_VALUE )); 
	printf("100 US dollars are equal to %f pounds\n", 
	ConvertCurrency(POUND_DOLLAR_FACTOR,US_DOLLAR_VALUE)); 
	printf("100 US dollars are equal to %f yens\n", 
	ConvertCurrency(YEN_DOLLAR_FACTOR,US_DOLLAR_VALUE) ); 
	/************************************************* 
	* Prompt user to press ENTER key to end program * 
	*************************************************/ 
	printf("\n\nPress Enter key to end..."); 
} 

// 
// Function ConvertCurrency returns the value of Factor times Dollars 
// 
float ConvertCurrency(float Factor, float Dollars) 
{ 
	float Result = 0.0; 
	Result = Factor * Dollars; 
	return(Result); 
}

Best regards,
Kobi Hikri.
  #4  
Old 08-Sep-2005, 15:32
Pinkyy Pinkyy is offline
New Member
 
Join Date: Sep 2005
Posts: 6
Pinkyy is an unknown quantity at this point

Miracle C Help


Thanks so much for your help!.. I really appreciate it! What is wrong is that when I go to put in a US dollar amount, the result is all zeros 000.
  #5  
Old 08-Sep-2005, 15:37
kobi_hikri's Avatar
kobi_hikri kobi_hikri is offline
Regular Member
 
Join Date: Apr 2005
Location: Israel
Posts: 431
kobi_hikri has a spectacular aura aboutkobi_hikri has a spectacular aura about
Quote:
Originally Posted by Pinkyy
Thanks so much for your help!.. I really appreciate it! What is wrong is that when I go to put in a US dollar amount, the result is all zeros 000.

Give me an example, I don't understand where you put the US dollar amount.

Kobi Hikri.
  #6  
Old 12-Sep-2005, 07:39
Pinkyy Pinkyy is offline
New Member
 
Join Date: Sep 2005
Posts: 6
Pinkyy is an unknown quantity at this point

C Help


to be honest I got off to a the wrong start in this class and really do not understand these formulas at all. I'm still in the book trying to teach myself, however I have another assignment that's due this friday that is a piggyback off of what has already been done. I would really appreciate it if you could assist me..... This is what I have to do....


Expand the “Currency Conversion” program to have a menu that allows the user to choose to which currency they wish to convert the US dollar amount. The program should loop back to the menu after each conversion until the user enters a value to exit the program. The program should display the "Currency Conversion" title, ask user for his name, ask user for US Dollar amount to convert (including name in the prompt), and then display a menu with the 5 conversion options. Once user picks a valid option, the program outputs a message with both the US dollar and equivalent amounts including the name of the currencies and only displaying two decimal places.

The program must contain at least one function other than main(). Insert preambles and comments in the program to document the program internally. Create a design flow chart (Word or PowerPoint format) for the program using the flow chart symbols discussed in class. Submit the flow chart and the source code of the program, each as separate attachments. Post to the Assignments Newsgroup on Friday. (15%)

This was the original assignment

Write a C program that displays a title, "Currency Conversion," and then display the names of five currencies and their equivalents to $100 US dollars. The program must use named constants (for any value that remains constant), variables and equations. The program should calculate the equivalency of $100 US dollars to the Euro, Japanese Yen, UK Pound, Germany Deutsche Marc, French Franc. For purposes of this exercise, use the following conversion factors:

1 US dollar = 0.926698 Euro
1 US dollar = 6.07874 Franc
1 US dollar = 120.300 Yen
1 US dollar = 1.81246 Deutsche Marc
1 US dollar = 0.619579 Pound

Once you have calculated the equivalency of $100 US dollars for each currency (using equations with variables and named constants), display the results on the screen. Be sure to label each result with the correct currency name. Before you display the 5 results, you should display "$100 US dollars is equivalent to:".

Insert preambles and comments in the program to document the program internally. Create a design flow chart (Word or PowerPoint format) for the program using the flow chart symbols discussed in class. Submit the flow chart and the source code of the program, each as separate attachments.

Thanks in advance for any assistance you can give me. I just wish I knew more about this stuff


Quote:
Originally Posted by kobi_hikri
Give me an example, I don't understand where you put the US dollar amount.

Kobi Hikri.
  #7  
Old 12-Sep-2005, 07:55
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough
Pinkyy,

You need to post what you have working so far. There are many different ways to do any of these tasks. It's the one you are working on that we need to know about.

Kobi cleaned up your code, did that one compile and work the way you thought it would? Since you say that it is a piggyback of the first assignment you should have some of you project already done.

Show us where you stand and then people will help you from there.

Mark
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
  #8  
Old 12-Sep-2005, 08:10
Pinkyy Pinkyy is offline
New Member
 
Join Date: Sep 2005
Posts: 6
Pinkyy is an unknown quantity at this point

Help From good guys :-)


That formula worked, however I was not able to view it too long because I didn't know where to input the getchar statement. I'll give you what kobi gave me, as well as another code that I have. I can't thank you enough guys, really..


Kobi's code:

CPP / C++ / C Code:
#include <stdio.h> 

#define EURO_DOLLAR_FACTOR		 		 0.926698 
#define FRANC_DOLLAR_FACTOR		 		 6.07874 
#define MARC_DOLLAR_FACTOR		 		 1.81246 
#define POUND_DOLLAR_FACTOR		 		 0.619579 
#define YEN_DOLLAR_FACTOR		 		 120.300 
#define US_DOLLAR_VALUE		 		 		 100.00 

float ConvertCurrency(float Factor, float Dollars); 

void main() 
{ 

		 printf("\t\t\t\t Currency Conversion\n"); 
		 printf("\n"); 

		 printf("100 US dollars are equal to %f euros\n", 
		 ConvertCurrency(EURO_DOLLAR_FACTOR,US_DOLLAR_VALUE )); 
		 printf("100 US dollars are equal to %f francs\n", 
		 ConvertCurrency(FRANC_DOLLAR_FACTOR,US_DOLLAR_VALUE)); 
		 printf("100 US dollars are equal to %f marcs\n", 
		 ConvertCurrency(MARC_DOLLAR_FACTOR,US_DOLLAR_VALUE )); 
		 printf("100 US dollars are equal to %f pounds\n", 
		 ConvertCurrency(POUND_DOLLAR_FACTOR,US_DOLLAR_VALUE)); 
		 printf("100 US dollars are equal to %f yens\n", 
		 ConvertCurrency(YEN_DOLLAR_FACTOR,US_DOLLAR_VALUE) ); 
		 /************************************************* 
		 * Prompt user to press ENTER key to end program * 
		 *************************************************/ 
		 printf("\n\nPress Enter key to end..."); 
} 

// 
// Function ConvertCurrency returns the value of Factor times Dollars 
// 
float ConvertCurrency(float Factor, float Dollars) 
{ 
		 float Result = 0.0; 
		 Result = Factor * Dollars; 
		 return(Result); 
}





[b]This is the other extended code I have also[/b] 


/*include the library*/
#include <stdio.h>
/*define the five currencies used for the conversion*/
#define Currency1 0.58
#define Currency2 2.50
#define Currency3 3.69
#define Currency4 21.00
#define Currency5 1.75
/*function prototyping*/
void menu (int *);
float calculateConversion(int, float);
/*main function of the program*/
int main()
{
     /*declare variables*/
     float us;
     float conversion;
     int choice;
     /*call user selection menu by reference*/
     menu(&choice);
     /*prompt user to enter amount of US to convert*/
     printf("Please enter an amount in US Dolalrs to convert: $");
     /*store user entry into memory*/;
     scanf("%f",us);
     /*call conversion function by value*/
     calculateConversion (choice, us);
     /*print results of conversion*/
     printf("The amount of that currency in US Dollars is: $%.2f\n", conversion);
     /*display results*/
     getchar();
     /*terminate program*/
     return 0;
}
/*function definition by reference*/
void menu(int *CHOICE)
{
     /*local variables for menu()*/
     int choice;
     /*show options to user*/
     printf("Welcome to the currency conversion program\n");
     printf("Press number 1 to 5 to select a currency to convert\n");
     printf("Press [1] for Pounds\n");
     printf("Press [2] for Deutchmarks\n");
     printf("Press [3] for Francs\n");
     printf("Press [4] for Pesetas\n");
     printf("Press [5] for Canadian Dollars\n");
     /*store choice in memory*/
     scanf("%d", &choice);
     /*set value of referenced variable*/
     *CHOICE = choice;
}
/*function definition by value*/
float calculateConversion(int CHOICE, float us)
{
   /*local variable for conversion*/
   float conversion;
   /*switch to user the case selected by user in reference funtion*/
   switch (CHOICE)
     {
       case 1:
            conversion=Currency1*us;
            break;
       case 2:
            conversion=Currency2*us;
            break;
       case 3:
            conversion=Currency3*us;
            break;
       case 4:
            conversion=Currency4*us;
            break;
       case 5:
            conversion=Currency5*us;
            break;
     }
/*returns the new value to the main function*/
return conversion;
}





Quote:
Originally Posted by cable_guy_67
Pinkyy,

You need to post what you have working so far. There are many different ways to do any of these tasks. It's the one you are working on that we need to know about.

Kobi cleaned up your code, did that one compile and work the way you thought it would? Since you say that it is a piggyback of the first assignment you should have some of you project already done.

Show us where you stand and then people will help you from there.

Mark
Last edited by LuciWiz : 13-Sep-2005 at 01:46. Reason: Please insert your C code between [c] & [/c] tags
  #9  
Old 12-Sep-2005, 08:17
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough
Pinkyy,

Go back and edit your post putting code tags around it. It is impossible to read otherwise.

Instructions in This Thread. You have a little bit of time to do it before your edit time expires. Once you see how, hit edit, add the code tags and we'll go from there.

Thanks,
Mark

The problem is that sometimes minor changes get made to your code when it is not tagged that make it hard to help.
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
  #10  
Old 12-Sep-2005, 08:41
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough
Ok, after a little formatting when I compile your code using gcc cygwin version on W2K I get the following.

Code:
$ gcc -Wall curr_convert.c -s -o CurrConvert curr_convert.c: In function `main': curr_convert.c:30: warning: format argument is not a pointer (arg 2)

then running it

Code:
$ CurrConvert Welcome to the currency conversion program Press number 1 to 5 to select a currency to convert Press [1] for Pounds Press [2] for Deutchmarks Press [3] for Francs Press [4] for Pesetas Press [5] for Canadian Dollars 5 Please enter an amount in US Dolalrs to convert: $1

Then it goes away never to return ...

Guess what, Your turn. :-)

Mark
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
 
 

Recent GIDBlogPython ebook by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 10:04.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.