I think what you are looking for is function pointers, eg:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
// these should have all of my declared functions
int start(void (*x)(), void (*y)(), void (*z)());
void pim();
void pmm();
void login();
void createa();
//my assignment wants me to have only one function used
int main()
{
start(&pim, &login, &createa);
return 0;
}
//This should be the start of the code
void pim()
{
cout << "Please select a letter from the menu below:" << endl;
cout << "l - Login" << endl;
cout << "c - Create New Account" << endl;
cout << "q - Quit" << endl;
}
// this is to post a menu after you make the first choice above
void pmm()
{
cout << "d - Deposit Money" << endl;
cout << "w - Withdraw Money" << endl;
cout << "r - Request Balance" << endl;
cout << "q - Quit" << endl;
}
//this is to login to the account
void login()
{
cout << "Okay, you're in" << endl;
}
// this is to create an account
void createa()
{
int id = 0;
int password = 0;
cout << "create an ID of two numbers" << endl;
cin >> id;
cout << "Make a password of 4 numbers" << endl;
cin >> password;
}
// Starts and is basically the entire project
int start(void (*x)(), void (*y)(), void (*z)())
{
x();
char choice = '';
cout << "Enter the choice that you want:";
cin >> choice;
switch (choice)
{
case 'l':
y();
break;
case 'c':
z();
break;
case 'q':
exit(0);
break;
default:
cout << "This is not a command" << endl;
}
return 0;
}
However, unless "function pointers" is the actual topic you are studying at the moment, then this is a very questionable design, even for a simple homework assignment. It would be cleaner and easier to read/manage to just call the functions directly instead, eg:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
// these should have all of my declared functions
int start();
void pim();
void pmm();
void login();
void createa();
//my assignment wants me to have only one function used
int main()
{
start();
return 0;
}
//This should be the start of the code
void pim()
{
cout << "Please select a letter from the menu below:" << endl;
cout << "l - Login" << endl;
cout << "c - Create New Account" << endl;
cout << "q - Quit" << endl;
}
// this is to post a menu after you make the first choice above
void pmm()
{
cout << "d - Deposit Money" << endl;
cout << "w - Withdraw Money" << endl;
cout << "r - Request Balance" << endl;
cout << "q - Quit" << endl;
}
//this is to login to the account
void login()
{
cout << "Okay, you're in" << endl;
}
// this is to create an account
void createa()
{
int id = 0;
int password = 0;
cout << "create an ID of two numbers" << endl;
cin >> id;
cout << "Make a password of 4 numbers" << endl;
cin >> password;
}
// Starts and is basically the entire project
int start()
{
pim();
char choice = '';
cout << "Enter the choice that you want:";
cin >> choice;
switch (choice)
{
case 'l':
login();
break;
case 'c':
createa();
break;
case 'q':
exit(0);
break;
default:
cout << "This is not a command" << endl;
}
return 0;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…