I've composed a code solely for practice, and I'm having trouble on calling a specific value in a function. Under the 'wallet' while loop, where I call the function with w+job(1), it loads the entire function rather than just adding the value of G. How can I just use the value of G, instead of loading the entire function?
#include <iostream>
#include <string>
#include <sstream>
#include <ctime>
#include <cstdlib>
usingnamespace std;
float job (float g);
int main()
{
float b;
b=0;
float a;
a=0;
float w;
w=0;
string sto;
string stt;
string wal;
cout << "Welcome to Consbank!\n";
cout << "Type 'withdraw', 'deposit', 'balance', 'job', or 'wallet'.\n";
cout << "'balance' shows the current amount of money in the bank.\n";
cout << "'deposit' adds money of choice to your account.\n";
cout << "'withdraw' subtracts money from your account.\n";
cout << "'job' gets you a job and makes money.\n";
cout << "'wallet' shows the current amount of money in your wallet\n";
cout << "Type 'exit' to exit the program.\n";
cout << "\n";
do{getline (cin,sto);
while (sto=="balance"){
b=b*100;
b= (int) b;
b= (float) b;
b= b/100.0;
cout << "$" << b;
cout << "\n";
sto = "c";
cout << "\n";
break;
}
while (sto=="wallet"){
w=w+job(1);
cout << "$" << w;
cout << "\n";
sto = "c";
cout << "\n";
break;
}
while (sto=="job"){
cout << "You got a job!\n";
job(1);
sto = "c";
cout << "\n";
break;
}
while (sto=="deposit"){
cout << "How much would you like to deposit?\n";
getline (cin,stt);
stringstream(stt) >> a;
cout << "\n";
if (a<=w)
b = b+a;
sto = "c";
if (a>w)
cout << "You don't have that much money!\n\n";
break;
}
while (sto=="withdraw"){
cout << "How much would you like to withdraw?\n";
getline (cin,stt);
stringstream(stt) >> a;
cout << "\n";
if (a<=b)
b = b-a;
w = a+w;
sto = "c";
if (a>b)
cout << "You don't have that much money!\n\n";
break;
}
while (b<=-1){
cout << "You can't have negative money!\n\n";
b=0;
}
while (b>=999999){
cout << "Get a better bank account! You can't store more than 999999!\n";
b=999999;
break;
}
} while (sto!="exit");
return 0;
}
float job (float g=0)
{
srand((unsigned)time(0));
int jsel;
jsel = rand() % 1+4;
g=0;
while (jsel==1){
cout << "You made $10.64!\n";
g=g+10.64;
jsel= rand() % 1+3;
break;
}
while (jsel==2){
cout<< "You made $25.00!\n";
g=g+25;
jsel= rand() % 1+4;
break;
}
while (jsel==3){
cout<< "You made $64.92!\n";
g=g+64.92;
jsel= rand() % 1+2;
break;
}
while (jsel==4){
cout<< "You made $34.50!\n";
g=g+34.50;
jsel= 1;
break;
}
}