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!