Thread: Money converter

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    18

    Money converter

    So the task is to build a program that converts swedish krona to euro using 4 functions

    *one that handles input
    returnvalue: input krona

    *one that converts to euro
    returnvalue: quantity of euro

    *one that writes the result

    *main function that takes care of the above

    All functions need to be called upon from main in order

    I have no idea what im doing here, could use some help!
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    /* program that converts euro to krona */
    float func (float krona,float euro, float result) {
    
    
    
    }
    
    
    int main(void)
    {
     float krona,euro,summa;
     float krona=0, euro=0, summa=0;
     printf("input a value for Krona: ");
     scanf(" %f", &krona);
     summa=berakning (x,y);
     printf("sum in Euro is: ");
    
     return 0;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The instructions seem pretty clear. There are a few ways to start, but one way that I might go about it is to define the first three functions with (almost) empty bodies. For example, starting with the "one that handles input":
    Code:
    float read_input_as_krona()
    {
        return 0.0f;
    }
    This way, I can write the logic for reading, converting and printing the output in the main function, and if I find that something is wrong about my assumptions about what parameters these functions need or what type of values they should return, I can fix these before I actually implement them.

    Furthermore, as I implement them, I can test them step by step.

    As it stands, it looks like your problem is that you completely ignored the instructions to separate the code into functions that do one thing and do it well.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wow money IS everything!!!
    By caroundw5h in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 03-27-2004, 03:27 PM
  2. In it for the money
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 02-28-2004, 02:17 AM
  3. any money anyone?
    By Fountain in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 08-14-2002, 07:58 PM
  4. the value of money
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 03-23-2002, 03:36 PM
  5. money
    By bob20 in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2001, 12:41 PM