This is my deposit implementation code:
-----------------------------------------------------------------------------
#include"deposit.h"
#include<iostream>
double Deposit::depositFunds(){
do {
std::cout << "Deposit options:" << std:: endl;
std::cout << "1 - Enter Any Number to deposit" << std::endl;
std::cout << "2- cancel transaction" << std::endl;
std::cout << "choose a deposit option (1-2)" << std::endl;
std::cin >> selectedOption;
switch (selectedOption) {
case 1:
std::cout << "Please the Number you want to deposit" << std::endl;
std::cin >> ValueToDeposit;
return balance = balance + ValueToDeposit;
isNotFinished = false;
break;
case 2:
isNotFinished = false;
break;
default:
std::cout << "Invalid option! Try again." << std::endl;
break;
}
} while (isNotFinished);
This is the header code of deposit
-----------------------------------------------------------------------------
#ifndef deposit_H
#define deposit_H
#include<iostream>
class Deposit {
public:
int selectedOption = -1;
bool isNotFinished = true;
double balance;
double ValueToDeposit;
This is the main
-----------------------------------------------------------------------------
#include <iostream>
#include <string>
#include"deposit.h"
using namespace std;
}
-----------------------------------------------------------------------------
My question is I can not return the deposit, which I input into the deposit.cpp file, to the int main, please help....
#include <iostream>
#include <string>
class Deposit {
public:
int selectedOption = -1;
bool isNotFinished = true;
double balance;
double ValueToDeposit;
double depositFunds();
};
double Deposit::depositFunds()
{
do {
std::cout << "Deposit options:""\n1 - Enter Any Number to deposit""\n2- cancel transaction""\nchoose a deposit option (1-2): ";
std::cin >> selectedOption;
switch (selectedOption) {
case 1:
std::cout << "Please enter the Number you want to deposit: ";
std::cin >> ValueToDeposit;
return balance += ValueToDeposit;
isNotFinished = false;
break;
case 2:
isNotFinished = false;
break;
default:
std::cout << "Invalid option! Try again.\n";
break;
}
} while (isNotFinished);
}
double balance = 0.0;
double interest = 0.01;
double valueToWithdraw;
double ValueToDeposit;
double finalbalance =0.0;
bool login();
int getUserOption();
void viewbalance();
int main()
{
Withdraw w;
Deposit d;
Interest i;
if (login()) {
int isNotFinished = true;
do {
switch (getUserOption()) {
case 1: viewbalance(); break;
case 2: w.withdrawCash(); break;
case 3: d.depositFunds(); break;
case 4: i.currentinterest(); break;
case 5: isNotFinished = false; break;
default: std::cout << "Invalid option! Try again.\n"; break;
}
} while (isNotFinished);
}
std::cout << "\n\t\t*****************************************\n""\n\t\tAmount Withdrawn :\t\t" << valueToWithdraw
"\n\t\tAmount Deposit :\t\t" << ValueToDeposit
"\n\t\tFinal Balance :\t\t\t" << finalbalance
"\n\t\t*****************************************\n";
return 0;
}
bool login()
{
std::string account = "professor";
int pin = 12345;
int givenPin = -1;
bool isAccountInvalid = true;
bool isPinInvalid = true;
std::cout << "Welcome!\n";
while (isAccountInvalid) {
std::cout << "Please enter your user name: ";
std::cin >> account;
if (account == "professor") { isAccountInvalid = false; }
else { std::cout << "Invalid username! Try again.\n"; }
}
while (isPinInvalid) {
std::cout << "Please enter your password: ";
std::cin >> givenPin;
if (givenPin == pin) { isPinInvalid = false; }
else { std::cout << "Invalid password! Try again.\n"; }
}
returntrue;
}
int getUserOption()
{
int selectedOption = -1;
std::cout << "*****************************************\n""Main menu:\n"" 1 - Balance\n"" 2 - Withdraw cash\n"" 3 - Deposit funds\n"" 4 - Interest Accrued\n"" 5 - Exit\n""*****************************************\n""Enter a choice: ";
std::cin >> selectedOption;
return selectedOption;
}
void viewbalance() { std::cout << "Your current balance is\n$" << balance << '\n'; }
If you try to compile the above code, it shows a long list of errors and the procedure stops.
Not all of them are connected with your class Deposit; on the contrary, it seems you need at least other two classes, Interest and Withdraw.
Actually, if we can’t even compile your code, it will be hard to find errors in it.
If you made it at least nearly compilable, I'm pretty sure you'd get more answers on this forum.