I have a program in c++ that keeps giving me the error message: Circular floNumb
ID: 3647208 • Letter: I
Question
I have a program in c++ that keeps giving me the error message: Circular floNumber <- floNumber.o dependency dropped. I believe I'm over-thinking this, can someone help. Here's the question and what I have:The company wants this program changed to indicate if you entered a floating number to say that, but also, indicate if the number to the left of the decimal is odd or even. If the number entered is a whole number, say that it is not a float number before indicating odd or even.
#include <iostream.h>
// checks whether the input is integer or not
// returns true if input is an integer value
// otherwise returns false
bool isInteger(char b[])
{
int i = 0;
while (b[i] != '')
{
if ((b[i] < '0' || b[i] > '9') && b[i] != '.')
return false;
i++;
}
return true;
}
// checks whether the given input is floating point value
// if yes returns true otherwise false
bool isFloat(char b[])
{
int i = 0;
while (b[i] != '')
{
if (b[i] == '.')
return true;
i++;
}
return false;
}
void main()
{
char buffer[50];
int i ;
cout << "Enter a number: " << endl ;
cin >> buffer;
cout << "The number you entered is " ;
if (isInteger(buffer))
{
i = atoi(buffer);
// checks for float or not
cout << "The number you entered is ";
if (isFloat(buffer))
cout << "a float value." << endl;
else
cout << "not a float value." << endl;
cout << "The number you entered is ";
if ( i / 2 * 2 == i)
cout << "even" << endl ;
else
cout << "odd" << endl ;
}
}
Explanation / Answer
please rate - thanks
I think you really are overthinking it.
try this
#include <iostream.h>
// checks whether the input is integer or not
// returns true if input is an integer value
// otherwise returns false
bool isInteger(float n)
{if(n==(int)n)
return true;
else
return false;
}
//returns integer portion of number if it's floating point
//otherwise converts number to integer
int convert(float n)
{return (int)n;
}
int main()
{
int i;
float num;
cout << "Enter a number: " << endl ;
cin >> num;
cout << "The number you entered is " ;
if (isInteger(num ))
cout << "an integer ";
else
cout << "a float value." << endl;
i=convert(num);
cout << "The number you entered is ";
if ( i%2==0)
cout << "even" << endl ;
else
cout << "odd" << endl ;
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.