Hi, thank you for taking your time off to help me with this.
I had tried to write a new code over the last few days. Please feel free to comment on them if you can.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include <iostream>
using namespace std;
//the pin is 752634
//can withdraw or deposit only
int bankbalance(){
int pinNo;
cout << "Please key in your 6 digits PIN number.\n";
cin >> pinNo;
int Ttries = 3; //total number of tries
int Utries = 1; //counting with respect to the first user input
while(pinNo != 752634 && Ttries - Utries != 0){
cout << "You have enter an invalid PIN number.\n";
cout << "Please try again.\n";
Utries++;
cin >> pinNo;
}
if(pinNo != 752634 && Ttries - Utries == 0){
cout << "You have no more chances.\n";
cout << "Your accound has been locked.\n";
cout << "Please re-set your PIN before trying.\n";
}
return pinNo;
}
float amountleft(float moneytrans){ //moneytrans == money transaction
float initialamt;
initialamt = 90678; //amount of money one has in the account
while(initialamt - moneytrans <= 0){
cout << "ERROR\n";
cout << "You cannot withdraw that amount.\n";
cout << "\tThis is because your savings is less than amount to be withdrawn.\n";
cout << "Please key in a new amount you wish to withdraw.\n";
cin >> moneytrans;
if(initialamt - moneytrans >= 0){
cout << "Withdrawal successful." << endl;
cout << "You have " << initialamt - moneytrans << endl;
break;
}
float finalamt = initialamt - moneytrans;
return finalamt;
}
}
float amtincreased(float moneydep){
float initialamt;
initialamt = 90678;
float finalamt = initialamt + moneydep;
cout << "You have " << finalamt << " in your current account.\n";
return finalamt;
}
int main()
{
if(bankbalance() == 752634){
cout << "You have key in the correct PIN numbers.\n";
}else {
return 0;
}
cout << "Please proceed with your transactions.\n";
cout << "Please 1 of the following options:\n";
cout << "1. Withdrawal\n \b2. Deposit\n";
int Typeoftransaction;
cin >> Typeoftransaction;
if(Typeoftransaction == 1){
cout << "Please key in the amount you wish to withdraw.\n";
float amountwith;
cin >> amountwith;
amountleft(amountwith);
}else if(Typeoftransaction == 2){
cout << "Please key in the amount you wish to deposit.\n";
float amountdep;
cin >> amountdep;
amtincreased(amountdep);
}
return 0;
}
|
As I am studying on my own, it is hard for me to determine which is the correct method. There are tons of advanced and complex answers online, which I cannot determine which is the right answer to my questions. I have entered them below for clarifications purposes.
I have the following questions:
1) The parentheses are meant for limits and boundary.
If I did not place any limits in it, it means that the code will just run on its own when called upon? When is it a good time to place limits and when is it not?
2) If I were to have a few functions, the name within each function can they be named the same? Why or why not?
3) How do choose between return functions and void functions? I know that return functions mean that you will get back a result, but you won't get one for void functions.
4)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
using namespace std;
int question4(){
int qns4;
cout << "Please key in a number.\n";
cin >> qns4;
return qns4;
}
int main()
{
cout << question4();
return 0;
}
|
Is it possible to just get the value of qns4 instead of running the whole line of code? I am not so sure about the advanced codings just yet. But as I was trying to type out the new codes above, this qns kind of struck me.