Advertisement

06.19.2006 at 10:19AM PDT, ID: 21891464
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.4

Currency Conversion Program

Asked by lgbrewer in Miscellaneous Programming

Tags: , ,


I have attempted to create a program that is crash proof but I seem to be missing the right codes to keep this program from crashing. I need for the program to not accept alpha, characters, or negative integers.  Can someone help, please!  See my futile attempt.  If I need a switch, where would I place it within the program to prevent any errors.

#include <stdio.h>

int main(void)        
{
/*
The conversion rates of five currencies equivalent to one US dollar.
Live mid-market rates as of 2006.06.18 16:29 Universal Time.  
*/
// Declare and define the conversion rates of five currencies equivalent to one US dollar.
/* Euro= Euro Dollars */
/* WON = South Korean WON */
/* Franc = Switzerland Franc */
/* Krone = Denmark Krone */
/* Krona = Sweden Krona */
    char cur[6][20]={"Euro ", "WON  ", "Franc", "Krone", "Krona", "Exit"}; //name of the five currencies
    float rates[5] ={1.23, 1232.55, 1.23, 6.01, 7.45}; //equivalent exchange rates
    float usd; /* US Dollars */
    float amount; /* Amount to Convert*/
    int r, i;
 
    printf("Written by: Luther Brewer\n\n");
    printf("\nThis Currency Conversion program converts each of the five currencies\n");
    printf("listed below into a US Dollar equivalent amount \n");
    printf("\nThe list of currencies available for conversion are (number, name): \n");
    for (i=0;i<6;i++) //a for loop to display the currencies to convert from
         {
    printf("\n%d, %s", i+1, cur[i]);
         }
     
choice:    printf("\n\nPlease select the number of the currency you want to convert to USD:\n\n");
           scanf("%d", &i);  
   
if ((i >6)||(i <=0))
    {
    printf("Choice is not available! \n\n");
    goto choice;
    }else if (i == 6){
        printf("\n\nHave a nice day! \n\n");
        }else{    
ask:        printf("\nHow much money do you want to convert to USD?: \n\n ");
        scanf("%f", &amount); //Wait for user's input
if (amount <=(float)0)    
             {  
               printf("\nCannot convert to US Dollars, if the number is zero or negative! \n\n");
               goto ask;
               }else{
           usd = amount /rates[i-1]; /*Convert to US Dollars*/
    // Calculation: finding the equivalent amount of the US dollar from the 5 input currencies.
       printf("\nYou will have %f US Dollars! \n\n", usd);
        }
        }
        fflush (stdin);
        getchar();
       return 0;/*End of program*/
 }  
Start Free Trial
 
 
[+][-]06.19.2006 at 11:18AM PDT, ID: 16936389

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Miscellaneous Programming
Tags: currency, programming, conversion
Sign Up Now!
Solution Provided By: julianH
Participating Experts: 3
Solution Grade: A
 
 
[+][-]06.19.2006 at 11:21AM PDT, ID: 16936422

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 14-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.19.2006 at 11:28AM PDT, ID: 16936472

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.20.2006 at 03:11AM PDT, ID: 16940948

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.01.2006 at 12:43PM PDT, ID: 17227409

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]08.07.2006 at 09:07PM PDT, ID: 17268722

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]08.12.2006 at 03:19AM PDT, ID: 17301445

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43