Jan 24, 2017 at 1:01pm Jan 24, 2017 at 1:01pm UTC
Write a c++ program to display a message if the number entered is whole or fraction number when the user enters a whole number or a fractional number. Pls help me. The compiler will accept input
Last edited on Jan 24, 2017 at 1:43pm Jan 24, 2017 at 1:43pm UTC
Jan 24, 2017 at 1:06pm Jan 24, 2017 at 1:06pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
using namespace std;
int main()
{
double number = 0;
cout << "Please enter a number: " ;
cin >> number;
// ???
return 0;
}
There you go. Just fill in the rest and it's all done.
Last edited on Jan 24, 2017 at 1:07pm Jan 24, 2017 at 1:07pm UTC
Jan 25, 2017 at 5:05pm Jan 25, 2017 at 5:05pm UTC
@Ekinne
Okay, here's a little more help..
if the number inputted minus int(number) does NOT equal zero, then the number inputted was fractional, otherwise, it's a whole number.
Jan 25, 2017 at 5:54pm Jan 25, 2017 at 5:54pm UTC
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 32 33 34 35 36
#include<iostream>
#include<string>
using namespace std;
int main()
{
char num[10];
bool check=true ;
int numInt=0;
double numDouble=0;
cout<<"\nEnter The Number : " ;
cin>>num;
for (int i=0;i<10;i++)
{
if (num[i]=='.' )
{
check=false ;
break ;
}
}
if (check==true )
{
cout<<"\nWhole Number" ;
numInt=atoi(num);// converting char to int
}
else
{
cout<<"\nFraction Number" ;
numDouble=atoi(num); // converting char to double
}
return 0;
}
Enter The Number : 1.24
Fraction Number
Enter The Number : 200
Whole Number
Last edited on Jan 25, 2017 at 5:55pm Jan 25, 2017 at 5:55pm UTC
Jan 25, 2017 at 6:04pm Jan 25, 2017 at 6:04pm UTC
There's the ratio class in the standard library which would be the same thing. Why reinvent the wheel?
Jan 25, 2017 at 7:47pm Jan 25, 2017 at 7:47pm UTC
Shh! I'm just messing with the guy because he excepts someone else to do his homework.