hi guys how are you,, I have a problem in my prpgram if anybody can fix it for me please, i shall be ver thankful,,
When i run my program, its a banking program, it ask, Do you want to do some banking, when I enter yes so after yes it stops and doesn,t proceed further, dont know why, is there any problem with for loop or while loop which i place after this, Please any body check it out and run it.. and fix it for me....
Thank you
below is the code:::::
//Practice6_2.cpp
#include <iostream>
#include <string.h>
#include<stdlib.h>
using namespace std;
void MakeDeposit(); //functions prototype??//
void MakeWithdrawal();
void GetBalance();
float balance = 0;
float newBalance = 0;
float adjustment = 0;
int main()
{
char response[256];
string moreBankingBusiness;
cout << "Do you want to do some banking? ";
cin >> moreBankingBusiness;
for (int i = 0; i < moreBankingBusiness.length(); i++) {
moreBankingBusiness[i] = toupper (moreBankingBusiness[i]);
}
while (moreBankingBusiness == "YES") {
cout << "What would you like to do? " <<"(1=Deposit, 2=Withdraw, 3=Get Balance): " <<endl;
cin.getline(response,256);
if (strlen(response) == 0) {
cout << "You must make a selection";
return 1;
}
else
if (atoi(response) < 1 |
atoi(response) > 3) {
cout << response <<
" - is not a valid banking function";
return 1;
}
if (atoi(response) == 1) {
MakeDeposit();
}
if (atoi(response) == 2) {
MakeWithdrawal();
}
if (atoi(response) == 3) {
GetBalance();
}
balance = newBalance;
cout << "Do you have more banking business? ";
cin >> moreBankingBusiness;
for (int i = 0;
i < moreBankingBusiness.length(); i++) {
moreBankingBusiness[i] =
toupper (moreBankingBusiness[i]);
}
} // end of while
cout << endl << endl << "Thanks for banking with us!";
return 0;
}
void MakeDeposit()
{
cout << "Enter the Deposit Amount: ";
cin >> adjustment;
newBalance = balance + adjustment;
cout << endl << endl <<
"*** SMILEY NATIONAL BANK ***" << endl << endl;
cout << "Old Balance is: " << balance << endl;
cout << "Adjustment is: +" << adjustment << endl;
cout << "New Balance is: " << newBalance
<< endl <<endl;
}
void MakeWithdrawal()
{
cout << "Enter the Withdrawal Amount: ";
cin >> adjustment;
newBalance = balance - adjustment;
cout << endl << endl <<
"*** SMILEY NATIONAL BANK ***" << endl << endl;
cout << "Old Balance is: " << balance << endl;
cout << "Adjustment is: -" << adjustment << endl;
cout << "New Balance is: " << newBalance
<< endl <<endl;
}
void GetBalance()
{
cout << endl << endl <<
"*** SMILEY NATIONAL BANK ***" << endl << endl;
cout << "Your current Balance is: " <<
newBalance << endl <<endl;
}
don't use any header file with .h in it so change include string.h to string
anytime you use a statement like this cin >> moreBankingBusiness; to input data follow that statement with cin.ignore(); to get rid of the newline left in the input stream from the user pressing enter
For character literals i use STRLEN() function and then to convert it into to string ATOI() function is used,,,,
but i remove header files include<string.h> and include<stdlib.h> then it shows me that STRLEN() and ATOI() are not declared in this scope...
Please guys i request you to please give me the solution