Home » Technical Support » Other » Need help with my C++ code
Need help with my C++ code [message #445206] |
Wed, 23 March 2011 12:15 |
_SSnipe_
Messages: 4121 Registered: May 2007 Location: Riverside Southern Califo...
Karma:
|
General (4 Stars) |
|
|
ok here is the story; I am still new at c++. I have only been taking the class for about a month. one assignment is make a program so its kinda like a vending machine for a deep fried twinkie (lol?), anyways if you see the code, i have a variable called money_pool which is used in a while loop, and different functions throughout the code. however, my professor said we can;t do global variables, so he recommended using call-by-reference (pointers) which he has barley started teaching us for about 5 minutes. So in other words, I don;t know about them yet and i'm trying to get my program to work with them. So far I messed up my code, like I said before it worked as global but since we can;t do that Iv been trying to figure out pointers in order to get it working, so I ask if someone can help me get this working. The problem is the variable money_pool....I hope....
I only ask if people dont suggest other ways to re arrange my functions of programs since they are ok, I only need to figure out how to get this to work like it used to
so please help me,
#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;
void money_message();
double insert_coin(double coin, double&);
void intro_message();
void end_message();
string selections(string string_pool);
void wrong_input(double&);
void welcome_banner();
void while_loop(double&);
char response; // to restart program
const int zer0 = 0;
const double three_fifty = 3.50;
int main()
{
double money_pool = 0;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
do {
intro_message();
while_loop(money_pool);
end_message();
} while ((response == 'y') || (response== 'Y'));
system("PAUSE");
return 0;
}
void while_loop(double& money_pool)
{
while (money_pool < three_fifty)
{
money_message();
}
}
//displays what user to input then puts it into a string that calls for selections function
void money_message()
{
using namespace std;
string string_pool;
cout << "Type quarter for .25" << endl;
cout << "Type nickle for .05" << endl;
cout << "Type dime for .10" << endl;
cout << "Type dollar for 1.00" << endl;
cout << endl;
cin >> string_pool;
selections(string_pool);
}
//function gets called and has different value for coin depending on users entry, if current value is 3.50 or above, gives back change if not display current money and remaining and continues to loop
double insert_coin(double coin, double& money_pool)
{
double change;
money_pool = money_pool + coin;
system("CLS");
if (money_pool > three_fifty)
{
welcome_banner();
change = money_pool - three_fifty;
cout << "Your change is: " << change << endl;
cout << endl;
}
else
{
welcome_banner();
cout << "You have inserted: " << money_pool << " So far" << endl;
cout << "Remaining Balance: " << three_fifty - money_pool << endl;
cout << endl;
}
return money_pool;
}
//if user at anytime types in wrong char or string
void wrong_input(double& money_pool)
{
using namespace std;
system("CLS");
welcome_banner();
cout << "***********************************" << endl;
cout << "Not a valid entry, Please try again" << endl;
cout << "***********************************" << endl;
cout << endl;
cout << "Remaining Balance for a Deep Fried Twinkie: " << three_fifty - money_pool << endl;
cout << endl;
}
// display intro message
void intro_message()
{
welcome_banner();
cout << "Want a deep fried twinkie?" << endl;
cout << "Only $3.50" << endl;
cout << endl;
}
// display after program ends
void end_message()
{
cout << "Enjoy your deep fried twinkie" << endl;
cout << endl;
cout << "Want another? (type y for yes, anything else quits)" << endl;
cin >> response;
system("CLS");
}
// my banner that should always be on top of screen to look pretty =]
void welcome_banner()
{
cout << "****************************" << endl;
cout << "* Welcome to Tanner's *" << endl;
cout << "* Deep Fried Twinkie *" << endl;
cout << "* Dispenser *" << endl;
cout << "****************************" << endl;
cout << endl;
}
// selection function takes result from money_message function and then runs coin function depending on which string, if none runs error function
string selections(string string_pool)
{
using namespace std;
double coin = zer0;
const double dollar = 1.00;
const double nickle = .05;
const double dime = .10;
const double quarter = .25;
if ((string_pool == "quarter") || (string_pool == "nickle") || (string_pool == "dime") || (string_pool == "dollar"))
{
if (string_pool == "quarter")
{
coin = quarter;
insert_coin(coin);
}
if (string_pool == "nickle")
{
coin = nickle;
insert_coin(coin);
}
if (string_pool == "dime")
{
coin = dime;
insert_coin(coin);
}
if (string_pool == "dollar")
{
coin = dollar;
insert_coin(coin);
}
}
else
{
// wrong_input(double&);
}
}
Quote: |
C:\Users\rcc\Documents\Untitled1.cpp In function `std::string selections(std::string)':
69 C:\Users\rcc\Documents\Untitled1.cpp too few arguments to function `double insert_coin(double, double&)'
154 C:\Users\rcc\Documents\Untitled1.cpp at this point in file
69 C:\Users\rcc\Documents\Untitled1.cpp too few arguments to function `double insert_coin(double, double&)'
159 C:\Users\rcc\Documents\Untitled1.cpp at this point in file
69 C:\Users\rcc\Documents\Untitled1.cpp too few arguments to function `double insert_coin(double, double&)'
164 C:\Users\rcc\Documents\Untitled1.cpp at this point in file
69 C:\Users\rcc\Documents\Untitled1.cpp too few arguments to function `double insert_coin(double, double&)'
169 C:\Users\rcc\Documents\Untitled1.cpp at this point in file
|
|
|
|
|
|
Need help with my C++ code
By: _SSnipe_ on Wed, 23 March 2011 12:15
|
|
|
Re: Need help with my C++ code
By: _SSnipe_ on Wed, 23 March 2011 13:16
|
|
|
Re: Need help with my C++ code
By: Hypnos on Wed, 23 March 2011 15:16
|
|
|
Re: Need help with my C++ code
By: _SSnipe_ on Wed, 23 March 2011 21:03
|
|
|
Re: Need help with my C++ code
By: Dover on Wed, 23 March 2011 21:25
|
|
|
Re: Need help with my C++ code
By: reborn on Thu, 24 March 2011 01:46
|
|
|
Re: Need help with my C++ code
|
|
|
Re: Need help with my C++ code
By: reborn on Thu, 24 March 2011 02:12
|
|
|
Re: Need help with my C++ code
By: Sir Kane on Thu, 24 March 2011 20:31
|
|
|
Re: Need help with my C++ code
By: _SSnipe_ on Thu, 24 March 2011 20:50
|
|
|
Re: Need help with my C++ code
By: reborn on Fri, 25 March 2011 01:54
|
|
|
Re: Need help with my C++ code
By: Sir Kane on Fri, 25 March 2011 08:16
|
|
|
Re: Need help with my C++ code
By: _SSnipe_ on Fri, 25 March 2011 09:42
|
|
|
Re: Need help with my C++ code
By: Omar007 on Fri, 25 March 2011 14:30
|
|
|
Re: Need help with my C++ code
By: _SSnipe_ on Sat, 26 March 2011 11:32
|
|
|
Re: Need help with my C++ code
By: Omar007 on Sat, 26 March 2011 17:31
|
Goto Forum:
Current Time: Wed Jan 15 05:50:05 MST 2025
Total time taken to generate the page: 0.00883 seconds
|