your code looks good
allow me to try to offer a couple of suggestions:
1.) each individual function definition does not have to "return zero." What I would recommend, is that you make your functions "void" functions.. so they do not have to return any value
Code:
//Function Prototypes
void add();
void sub();
void mul();
void div();
So now.. your function definitions will look similar to this..
for example
Code:
void add()
{
int x, y;
cout<<"Please input two numbers to be added together."<<endl;
cin>>x>>y;
cout<<"The result is: "<<x+y;
main();
}
2.) This is kinda knit-picky.. but instead of using objects named, "x" and "y".... try focusing on, "self documenting code" technique.. for example:
Code:
int div()
{
int x, y;
cout<<"Please a number to be devided by another."<<endl;
cin>>x>>y;
cout<<"The result is: "<<x/y;
main();
return 0;
}
could be:
Code:
void div()
{
int first_number, second_number;
cout<<"Please a number to be devided by another."<<endl;
cin >> first_number >> second_number;
cout<<"The result is: "<< (first_number / second_number);
main();
}
first_number and second_number have a little more meaning than 'x' and 'y'
3.) insert "using namespace std;" after your preprocessor directive:
Code:
#include<iostream>
using namespace std;
also.. notice that I changed #include<iostream.h> to #include<iostream> which is now the modern convention... (the .h suffix is used mainly with older compilers)
4.) I'm not sure if you are familiar with the "do/while" loop structure.. but it is a good way to make your program more robust.. allowing your switch case structure to be executed as many times as desired. Here is some of my own example code:
Code:
#include<cstdlib> //Provides "EXIT_SUCCESS" and "system( )"
#include<iostream> //Provides "cin" and "cout"
#include<cctype> //Provides "toupper( )"
using namespace std;
int main()
{
data stack;
char choice = 'x';
system("cls");
do
{
try
{
stack.print_menu();
choice = toupper(get_user_command());
switch(choice)
{
case 'A': stack.push();
break;
case 'R': stack.pop();
break;
case 'V': stack.view_array();
break;
case 'E': stack.erase_array();
break;
case 'Q': exit_message();
break;
default: throw choice;
}
}
catch(char choice)
{
cout << "\n\t" << choice << " is an invalid entry. Please try again." << endl;
}
cout << endl;
system("pause");
system("cls");
}while (choice != 'Q');
return EXIT_SUCCESS;
}
Hope this helps shed some light on your question