help

i want to do this calculating but it tells me error.
I know that with float i cant use this(%),but if i want how could i use it,is there any way?

look this and if you know plz help me.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<iostream>



using namespace std;

main()
{


float g;
int a
float b;
a=5.14;
b=2;
g=a%b;
cout<<g;
}
Given that using a float makes no sense there, what exactly are you trying to do? What answer to

5.14%2

are you looking for?
For example you can write

g = a % static_cast<int>( b );

Take into acccount that after the statement

a=5.14;

a will have value equal to 5 because a is defined as int.
i want to do this:
5.14%2=1.14

how will do it?
when i run it ,it tell me that float cant take this(%),so what should i do?
The operator % is applied only to integral types. So you can rewrite your statement the following way

1
2
3
float x = 5.14;

float y = x - static_cast<int>( x ) / 2;
what does g = a % static_cast<int>( b ); means ??!
The same as a % b only b was converted to int.
Topic archived. No new replies allowed.