whole no. and decimal

im trying to put my input able to get numbers entered in whole and decimal.because i need to increment it for the next process.

The problem is my cin can only accept whole number....how can i make it to accept also in decimal?

1
2
3
4
5
float my_float;
cin >> my_float;//accepts numbers like 5, -5, 5.1, 5.1e+1 (exponential notation)

int my_int;
cin >> my_int;//accepts only 5 or -5. 

Though I don't really understand what you're trying to do..
http://ideone.com/PxUJx

Do you mean like this?
ive used the float but error came out...the error says " [Warning] converting to `int' from `float' " ...is there anything i need to fix in the code?
newlearner wrote:
.is there anything i need to fix in the code?

You need to show us the code that is causing the error.
i have declare the 'intv' and 'a' as int......




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

if (maxNum<=360 && minNum>=0)
             {
             
                cout << "\n\tDegree\t\tSine\t\t\tCosine\n";
                cout << "\t-----------------------------------------------" << endl;
          
                for (a=minNum; a<=maxNum; a=a+intv)     
                {
                 sine = sin (a * pi/b);
                 cosine = cos (a * pi/b);
                 
                  
                 cout.precision(2);    
                 
                 printf ("\t%d\t\t%6.4f\t\t\t%6.4f\n", a, sine, cosine);
                }        
            
            }











It's only a warning. It's there because conversion from float to int rounds down. float 1.5 will become 1. This isn't always a bad thing. Though I don't see where in your code you're doing that. Unless you declared sine and cosine as integers..
The printf format %d is for integers. I'm guessing 'a' is a float?
Topic archived. No new replies allowed.