I am tring to set an array with its values to zero within a constructor, but I can't get it to work. I have created an array with the size of 5 in the private of my class. I want the values of my array to be set at zero. Can anybody help me out with this??
#include <iostream>
#include <cstdlib>
using namespace std;
class NumberFun {
public:
NumberFun( ); // parameterless default constructor
void squarecube();
void history();
private:
int cube[5]; // Array for squarecube
};
int main() {
NumberFun mynum;
int selection;
cout << "Welcome to Number Fun\n\n";
while ( selection != 0 ) {
cout << "********** Main Menu **********\n\n";
cout << "Please make a selection" << endl << endl;
cout << " * 0 - quit" << endl;
cout << " * 1 - TabFive" << endl;
cout << " * 2 - SquareCubes" << endl;
cout << " * 3 - CalorieCounter" << endl;
cout << " * 4 - Show historical output" << endl << endl;
cin >> selection;
switch (selection){
case 0:
break;
case 1:
mynum.tabfive( );
break;
case 2:
mynum.squarecube( );
break;
case 3:
mynum.caloriecounter( );
break;
case 4:
mynum.history( );
break;
default:
cout << "Invalid. Select 0-4.\n\n";
}
}
cout << "\nThank You for using Number Fun!!\n\n";
system("pause");
return 0;
}
NumberFun::NumberFun() { // default constructor
numin = 0;
ate = 0;
cube[5];
}
void NumberFun::squarecube() {
// Heading
cout << "\n********** SquareCube **********\n\n";
// Prompt user to enter 5 different integers
cout << "Enter 1st Integer : " ;
cin >> cube[0];
cout << "Enter 2nd Integer : " ;
cin >> cube[1];
cout << "Enter 3rd Integer : " ;
cin >> cube[2];
cout << "Enter 4th Integer : " ;
cin >> cube[3];
cout << "Enter 5th Integer : " ;
cin >> cube[4];
// Prints a table whose first column has the five integers entered, second column corresponding
// squares of the first column and third the cubes. Seperated by tabs.
cout << "\nInt\tSqr\tCube\n" ;
cout << cube[0] << "\t" << cube[0]*cube[0] << "\t" << cube[0]*cube[0]*cube[0] << endl;
cout << cube[1] << "\t" << cube[1]*cube[1] << "\t" << cube[1]*cube[1]*cube[1] << endl;
cout << cube[2] << "\t" << cube[2]*cube[2] << "\t" << cube[2]*cube[2]*cube[2] << endl;
cout << cube[3] << "\t" << cube[3]*cube[3] << "\t" << cube[3]*cube[3]*cube[3] << endl;
cout << cube[4] << "\t" << cube[4]*cube[4] << "\t" << cube[4]*cube[4]*cube[4] << endl << endl;
system("pause");
cout << endl << endl;
}
void NumberFun::history() {
// Heading
cout << "\n********** History **********\n\n";
// Display the History from TabFive
cout << "---TabFive" << endl << endl;
cout << " The number entered is " << numin << endl << endl;
cout << "---SquareCube" << endl << endl;
cout << " The Five Numbers entered are " << cube[0] << " " << cube[1]
<< " " << cube[2] << " " << cube[3] << " " << cube[4] << endl << endl;
cout << "---CalorieCounter" << endl << endl;
cout << " The number of cookies the user entered is " << ate << endl << endl;
system("pause");
cout << endl << endl;
}