Oct 19, 2011 at 7:10am UTC
I want to know that if there is any solution for me to run the switch case well. I would like to know that if there is any solution to run the three cases well. Thank you.
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
class alkali
{
char element[5];
public:
void lithium(char element[5])
{
cout << "Name:" << element << endl;
}
};
class steel
{
char element[5];
public:
void sss(char element[5])
{
cout << "Name: " << element << endl;
}
};
int main(int argc, char *argv[])
{
char element[5];
cout << "Please enter element" << endl;
cin >> element;
switch(element)
{
case 'E':
{
alkali a;
a.lithium(element);
break;
}
case 'FW':
{
steel ds;
ds.sss(element);
break;
}
case 'FWF':
{
asd ds;
ds.sss(element);
break;
}
default:
{
cout << "Freak!" << endl;
break;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
Oct 19, 2011 at 7:44am UTC
anyone know the way to combine element[0],element[0,1] and element[0,1,2] together?
Oct 19, 2011 at 9:37am UTC
This is the C++ forum. You should be using std::string rather than C-strings/char-arrays.
In any case, switch() won't work on anything besides int or char [or anything convertable to int, but I have no idea what that includes].