I have a switch statement with 2 functions. I put 2 test cout
statements, both of which get displayed, but only one function is actually performed. A third test cout
statement is made in the second function, but that does not get displayed. "switch" and "switch2" get displayed.
Yes, I am new to programming.
Thanks for your help, been scratching my head on this for a while.
int main ()
{
char a;
int min, max, num1;
min = 0;
max = 0;
num1 = 0;
cout << "Please select from the following:\n\n"
<< setw(10) << " " << setw(15) << "(S) Square "
<< setw(10) << " " << setw(15) << "(C) Cube " << endl << endl
<< setw(10) << " " << setw(15) << "(F) Fourth Power"
<< setw(10) << " " << setw(15) << "(Q) Quit " << endl;
cin >> a;
while (!cin.good())
{
cout << "Please try again." << endl;
cin.clear();
cin.ignore(80, '\n');
cin >> a;
}
switch (a)
{
case 's':
case 'S':
minMax (&num1, &min, &max);
cout << "switch" << endl;
square (&num1, &min, &max);
cout << "switch2" << endl;
break;
case 'c':
case 'C':
minMax (&num1, &min, &max);
cube ( &num1, &min, &max);
break;
case 'f':
case 'F':
minMax (&num1, &min, &max);
fourth ( &num1, &min, &max);
break;
default:
cout << "switch3" << endl;
return 0;
break;
}
}
int square (int *num1, int *min, int *max)
{
int a,b,c,line;
b = *min;
c = *max;
a = *num1;
line = 0;
while (a <= c)
{
cout << "square" << endl;
b = a;
a = a * a;
output (&a);
line++;
if (line = 10)
{
cout << endl;
line = 0;
}
}
return a, b, c;
}