Thread: Need help with FMOD Using Floats

  1. #1
    Registered User
    Join Date
    Apr 2014
    Posts
    2

    Need help with FMOD Using Floats

    Hi Guys,

    I'm trying to put together a little project / game for a interview I have tomorrow, I know left it a little late, but am having problems getting the final piece which is displaying the lemon wastage working accurately.
    I'll post my code below everything works but the FMOD line 92, that is returning zero. Code below.

    Code:
    .
    
    
    // include required libraries.
    #include<stdio.h>
    #include<stdlib.h>
    #include<iostream>
    #include<string.h>
    
    
    int main(int argc, const char*argv[]) // start main program.
    {
        int iChoice = 5; // declare and set variables.
    
    
        std::cout << " Welcome to the lemonade stand game\n"; // welcome player to lemonade stand game.
    
    
        // place menu here and get users choice.
        std::cout << " Menu\n";
        std::cout << " -----\n";
        std::cout << " \n";
        std::cout << " 1: Play Game.\n";
        std::cout << " 2: View Instructions.\n";
        std::cout << " 3: View Credits.\n";
        std::cout << " 4: Exit Program.\n";
        std::cin >> iChoice;
    
    
        while (iChoice < 5) // this will make the program loop.
        {
            if (iChoice == 1) // this checks if the user entered 1.
            {
                std::cin.clear();
                fflush(stdin);
    
    
                std::cout << " Get ready for a amazingly cool game.\n"; // welcome player to game.
    
    
                // set variables.
                int iResult;
                const char CCHARACTER[10]
                    = { 'n', 'i', 'c', 'h', 'o', 'l', 'a', 's' };
                const float fWaterPerCup = .75;
                const float fLemonPerCup = .25;
                const float fSugarPerCup = .25;
                const float fCostPerCup = 1.05;
                char cEnteredName[15];
                int iIngredientsRequired;
                int iLemonadeDesired;
                float fWaterRequired;
                float fSugarRequired;
                float fLemonsRequired;
                float fLemonWastage;
                float fTotalCost;
    
    
                std::cout << " Please enter your first name.\n"; // ask user for name.
    
    
                gets_s(cEnteredName); // store name entered.
                iResult = strcmp(CCHARACTER, cEnteredName); // compare names
    
    
                if (iResult == 0) // test if string is same as mine.
                {
                    std::cout << " The string you entered is the same as mine.\n"; // string is the same.
                }
                else
                {
                    std::cout << " The string you entered is not the same as mine.\n"; // string is not the same.
                }
    
    
                std::cout << " Please enter how many cups of lemonade you desier.\n"; // ask for lemonade required.
                std::cin >> iLemonadeDesired; // store lemonade required.
    
    
                // calculate ingredients required.
                fWaterRequired = iLemonadeDesired * fWaterPerCup;
                fSugarRequired = iLemonadeDesired * fSugarPerCup;
                fLemonsRequired = iLemonadeDesired * fLemonPerCup;
    
    
                // list  ingredients required.
                std::cout << "Water required is: \n" << fWaterRequired << std::endl;
                std::cout << "Sugar required is: \n" << fSugarRequired << std::endl;
                std::cout << "Lemons required is: \n" << fLemonsRequired << std::endl;
    
    
                fLemonWastage = fmod(iLemonadeDesired,fLemonsRequired); // calculate lemon wasted.
    
    
                std::cout << "Lemon wasted is: \n" << fLemonWastage << std::endl; // display lemon wasted.
    
    
                fTotalCost = fCostPerCup * iLemonadeDesired; // calculate total cost.
    
    
                std::cout << "The total cost is: $" << fTotalCost << std::endl; // display cost.
            }
    
    
            if (iChoice == 2) // this checks if the user entered 2.
            {
                std::cout << " Instructions have not been completed yet please check back later.\n \n";
            }
            if (iChoice == 3) // this checks if the user entered 3.
            {
                //declare required variables.
                const int YEAROFDEVELOPMENT = 2011;
                float fGameVersion = 1.0;
                //print details.
                std::cout << " Program creators name is: Nicholas Mirabito.\n";
                std::cout << " My favorite hobby is: programming.\n";
                std::cout << " My company name is: Creative Games.\n";
                std::cout << " The year of development is: " << YEAROFDEVELOPMENT << std::endl;
                std::cout << " The game version is: " << fGameVersion << std::endl;
            }
            if (iChoice == 4) // this checks if the user entered 4.
            {
                std::cout << " Thank you for playing. The program will now exit.\n"; // confirmation the program will exit.
                system("pause"); // pause so player can read screen.
                return 0; // exit the program here.
            }
            // place menu here and get users choice.
            //(this is because the top one is not reached again by this program.)
            // printing menu.
            std::cout << " Menu\n";
            std::cout << " -----\n";
            std::cout << " \n";
            std::cout << " 1: Play Game.\n";
            std::cout << " 2: View Instructions.\n";
            std::cout << " 3: View Credits.\n";
            std::cout << " 4: Exit Program.\n";
            std::cin >> iChoice;
        }
        system("pause"); // pause console.
        return 0;// exit program.
    }
    .

    Sorry its a bit messy the entry box here is a bit too narrow.

    Any advice on how to get the FMOD line 92 working accurately and getting the accurate lemon wastage would be greatly appreciated.

    Thanks!

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Read about fmod fmod - C++ Reference
    Pay attention to the parameter types.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    This should be moved to the C++ thread.
    Fact - Beethoven wrote his first symphony in C

  4. #4
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    I remember playing Lemonade Stand on the Commodore 64 emulator.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Moved to C++ programming forum.
    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

  6. #6
    Registered User
    Join Date
    Apr 2014
    Posts
    2
    Actually come to think of it I'm doing that whole line completely wrong aren't I? Using modulus for .25 is never going to give me anything but zero. Unless you swap the variables around then if I select 1 drink it gives you .25 wastage when it should be .75. So how would you write the line to calculate the wastage? Dam this is what happens when you start programming than leave for such a long time you forget everything!
    Last edited by AJ847.63; 04-03-2014 at 03:21 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to use FMOD
    By Mosgrave in forum Tech Board
    Replies: 2
    Last Post: 03-14-2012, 11:37 AM
  2. fmod()
    By Josh@Dreamland in forum C Programming
    Replies: 13
    Last Post: 07-12-2008, 10:05 PM
  3. fmod()
    By salvadoravi in forum C Programming
    Replies: 1
    Last Post: 01-21-2008, 06:55 AM
  4. fmod %
    By robwhit in forum C Programming
    Replies: 1
    Last Post: 07-08-2007, 04:10 AM
  5. Help With Fmod Music Lib!
    By Blizzarddog in forum Game Programming
    Replies: 0
    Last Post: 05-29-2003, 12:29 PM