Can i have an array value in a case structure ? The program repeat storing 10 calculating value's to be displayed how will the array be intialized in the case structure? here is the basic layout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// float value [];//
do {
// program to be repeated //
case :1 {
//calculation//
}
} while (condition) ;
Yes and no. You most certainly can use the value of a certain object in an array in a switch statement.
1 2 3 4 5 6 7 8 9 10
int intArray[2] = {5, 1};
switch(intArray[0])
{
case 5:
cout << "intArray[0] equals 5" << endl;
break;
default:
break;
}
However, you should never use a floating point variable in an equality comparison. Switch statements can only be used to compare constants, and floats vary depending on how they're calculated and where they're truncated, so it's not really viable to use switch statements in the case of floating point variables. Unless you're doing something like: