-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisfloat.cpp
More file actions
37 lines (31 loc) · 1.24 KB
/
isfloat.cpp
File metadata and controls
37 lines (31 loc) · 1.24 KB
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
37
//===============================================START OF MODULE=========================================================================
#include<stdio.h>
#include<string>
#include<cctype>
#include<math.h>
extern "C" bool isfloat(char[]);
bool isfloat(char digit[]){
bool trueNumber = true;
unsigned int dots = 0;
long unsigned startIndex = 0; //Used for index in for loop
//Checking for any '+' or '-' on first index
if(digit[0] == '-' || digit[0] == '+'){ //If negative or positive sign located, shift index up
startIndex++;
}
else if (!isdigit(digit[0])){
trueNumber = false;
}
while(digit[startIndex] != '\0'){
if(!isdigit(digit[startIndex])){
if(digit[startIndex] == '.'){
//Decimal point found
dots++;
if(dots > 1) trueNumber = false; //If more than one decimal point is inputted.
}
else trueNumber = false;
}
startIndex++;
}
return trueNumber;
}
//===============================================END OF MODULE============================================================================