Question
I need correction of this program C++ Im getting this error messages warning C4244: 'argument': conversion from 'time_t' to 'unsigned int', possible loss of data
I need correction of this program C++
Im getting this error messages
warning C4244: 'argument': conversion from 'time_t' to 'unsigned int', possible loss of data source.cpp(137): error C3861: 'withdrawal': identifier not found source.cpp(147): error C3861: 'withdrawal': identifier not found source.cpp(180): error C2082: redefinition of formal parameter 'amount' 1>Done building project "Project1.vcxproj" -- FAILED. ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
// bring in our libraries
#include
#include
#include
#include
#include
#include
using namespace std;
// Entry point to the application
const int EXIT_VALUE = 5;
const float DAILY_LIMIT = 400.0f;
const string FILENAME = "Account.txt";
// create balance variable
double balance = 0.0;
//prototypes
void deposit(double* ptrBalance)
{
// det deposit and validate it
float deposit = 0.0f;
do {
cout << "/nEnter deposit amount: ";
cin >> deposit;
if (cin.fail()) // did they give us a character instead of a number?
{
cin.clear(); // clears fail state
cin.ignore(INT16_MAX, ' '); // clears key board buffer
cout << " Error. Please use numbers only. " << endl;
deposit = -1; // sset deposit to a "bad number
continue; // restart the loop
}
else if (deposit < 0.0f)
cout << " Error. Invalid deposit amount. " << endl;
}
while (deposit < 0.0f);
// how do we get the double value located at the pointer?
// Dereference it using an asterisk!
*ptrBalance += deposit; // same as : *ptrBalance = *PtrBalance
cout << fixed << setprecision(2) << " Current ptrBalance: $" << *ptrBalance << endl; // notice the asterisk
}
int main()
{
// pause
cout << " Press any key to continue...";
_getch();
ifstream iFile(FILENAME.c_str());
if (iFile.is_open())
{
// did the file open? if so read the balance
iFile >> balance;
iFile.close();
}
else
{
// if the file did not open or does not exist, create
// random number for the starting balance
srand(time(0));
const int MIN = 1000;
const int MAX = 10000;
balance = rand() % (MAX - MIN + 1) + MIN;
}
cout << fixed << setprecision(2) << "Starting Balance :$" << balance << endl;
// let's create a pointer and set it to the balance variable location
double* ptrBalance = &balance; // & means "address of the pause before we clear the screen
cout << " Press any key to continue...";
_getch();
// create loop variable BEFRORE the loop
short choice = 0;
//start the application loop
do
{
// show the menu
system("cls"); // clears the console screen -- for Mac , use system("clear")
cout << "Menu " << endl;
cout << "1) deposit " << endl;
cout << "2) withdrawal" << endl;
cout << "3) check Balance" << endl;
cout << "4) quick $40 " << endl;
cout << "5) Exit" << endl;
// get user input
cout << " Enter your choice: ";
cin >> choice;
// run cose based on the users choice
switch (choice)
{
case 1:
//cout << "making a deposit ..." << endl;
deposit(ptrBalance); // passing a pointer so only four by tes have to go across the system bus!
break;
case 2:
//cout << "making a withdrawal..." << endl;
withdrawal(ptrBalance, DAILY_LIMIT);
break;
case 3:
//cout << "showing the current balance..." << endl;
cout << fixed << setprecision(2) << " Current Balance: $" << balance << endl;
break;
case 4:
//cout << " getting a quick $40...." << endl;
withdrawal(ptrBalance, DAILY_LIMIT, 40.0f);
break;
case 5:
cout << " goodbye" << endl;
break;
default:
cout << " Error Please from the menu. " << endl;
break;
}
// pause
cout << " Press any key to continue...";
_getch();
}
while (choice != EXIT_VALUE);
// now that the application is over, write the new balance to the file
ofstream oFile(FILENAME.c_str());
oFile << balance << endl;
oFile.close();
return 0;
}
void withdrawal(double* ptrBalance, float dailyLimit, float amount)
{
float amount = 0.0f;
cout << " Enter withdrawal amount : ";
cin >> amount;
// call the overloaded method version that takes
// the balance , dailyLimit , and withdrawal amount
withdrawal(ptrBalance, dailyLimit, amount);
// take away money from the account and show the balance
if (amount > dailyLimit)
{
cout << " Error. Amount exceeds daily limit." << endl;
}
else if (amount > *ptrBalance) // notine the asterisk to dereference the pointer!
{
*ptrBalance -= amount; // same as : *ptrBalance = *prtBalance - amount ;
cout << " Here is your cash: $ " << amount << endl;
}
cout << fixed << setprecision(2) << " Current Balance: $" << *ptrBalance << endl;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started