Statements vs equations

Posted on 2007-10-06
Last Modified: 2010-08-05
I am haveing a problem. I am supose to use hard coded equations  to get this results.

Currency Conversion
1.00 Euro = 1.28 US Dollar
1.00 UK Pound = 1.87 US Dollar
1.00 Japanese Yen = 0.01 US Dollar
1.00 Canadian Dollar = 0.82 US Dollar
1.00 Australian Dollar = 0.77 US Dollar

I got the above display with this...

#include <studio.h>


//Title of program
printf("Currency Conversion\n");
//List of Conversions
printf("1.00 Euro = 1.28 US Dollar\n");
printf("1.00 UK Pound = 1.87 US Dollar\n");
printf("1.00 Japanese Yen = 1.01 US Dollar\n");
printf("1.00 Canadian Dollar = 0.82 US Dollar\n");
printf("1.00 Australian Dollar = 0.77 US Dollar\n");


but they are not can I convert these statments to equations?
Question by:alwright1975
    LVL 7

    Expert Comment

    Are you trying to make program which will convert currencies?

    Author Comment

    yes, my fist step is to use hard coded equations to display what i showed above. Then I have to build on it to write one with a menu to chose which converstion, then to allow user to enter amount to convert and I am lost and confused?
    LVL 7

    Accepted Solution

    I suppose you need this?

    #include <stdio.h>

    int main() {
        int choice;
        double coef, amount, res;
        printf("Choose currency:\n\n");
        printf("\t1.) Euro\n");
        printf("\t2.) UK Pound\n");
        printf("\t3.) Japanese Yen\n");
        printf("\t4.) Canadian Dollar\n");
        printf("\t5.) Australian Dollar\n\n");

        printf("Your choice is: ");
        scanf("%d", &choice);
        switch (choice) {
               case 1: coef = 1.28; break;
               case 2: coef = 1.87; break;
               case 3: coef = 0.01; break;
               case 4: coef = 0.82; break;
               case 5: coef = 0.77; break;
        printf("\nEnter amount: ");
        scanf("%lf", &amount);
        res = amount * coef;
        printf("Amount in American dollars: %6.2Lf.", res);
        return 0;
    LVL 7

    Expert Comment

    This program:

    - Prints the menu.
    - Reads the choice to the variable "choice".
    - Depending of what did user choose, we have different coefficients.
    - Reads the amount of money.
    - Multiplies the amount of money with coefficient.
    - Prints the result.


    * '\n' - new line
    * '\t' - tab
    * when you want to read some variable you must use & in front of it.
    * when you want to print it you don't use &.
    * when you want to read or print double variable you must use %lf in printf or scanf.
    LVL 53

    Expert Comment

    UrosVidojevic, please don't just give code that is meant for an assignment. The goal for alwright1975 is to learn something - not to just get a solution handed on a platter.

    alwright1975, what you want to do is store the conversion values in some variables (an array would be nice). Then, you can retrieve those values, and use them to show the conversion rates to the user.

    Take a look at the reference page for printf eg. :


    Note that there are several format specifiers you can use to show variables. Take a look at the example code on that page too.

    Author Comment

    Thank you both, Infinity08 and UrosVidojevic all was very helpful. Also even thought it was great code I still have to tweak it to fit the requirment for my 3 assignments. This gave me an idea of how it works and what I needed to do to change it to the requirment. Thank you both again very much!!!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
    This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
    The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now