I'm making a program with dev-c++ that needs "float" to declare and not "int" because it needs precision on numbers.(sorry for bad english i hope you'll understand). Here is the first part of the code:
and then it continues.. but I need help on this part. Instead of "int p,cat1,cat2,i,i2,cat,catot;" i need "float p,cat1,cat2,i,i2,cat,catot;" but if i put "float" it tells me error: switch quantity not an integer.
what should i do? please hep me.
The cases are all right because if i use "int" the program works perfectly exept for one thing:
case 1:
it moltiplies an input number by another input number. If the number1 is 2 then the number2 is 3 it gives me result: 6.(and that's all right)
but if number1 is 2,5 (for example) it wont work because it needs "float" for numbers with ","
I'm assuming comma "," really means decimal ".". Well you could just use a bunch of if then else statements but that's sloppy. I wanted a few case statements to see if we can find a common element among them and eliminate the switch case all together. Could you post like three of them?
The cases of a switch statement must be integers or convertible to integers (chars). Using floats or doubles probably wouldn't work anyway, because of floating-point imprecision.
I think you're trying to do too much at once. What happens if I want to subtract the product of my elements? But my first number is 2? You should prompt the user for a number first then use that in the switch case statement, THEN you prompt him for the data to be used in the mathmatical operations.