webmastadj84
IS-IT--Management
I need some help. I am trying to vaildate a string. The user needs to insert a number no bigger than 30 characters long and needs to be number. So no more than one "." and one "-". Also, I can't have any alpha charaters (i.e. a,b,c,d,e,f....).
This is what I have so far:
===============================================
#include <iostream>
#include <string>
using namespace std;
float DoubleANumber(float Num) {
return (Num*2);
}
int main() {
char ANumber[30];
bool InputValid = true;
cout << "Enter a number: ";
cin.getline(ANumber,30);
int LoopCount = 0;
int Decimals = 0;
int Negitave = 0;
int CharSize = strlen(ANumber);
while (CharSize > LoopCount) {
if (ANumber[LoopCount] = ".") {
Decimals = Decimals + 1;
}
if (Decimals > 1) {
InputValid = false;
}
LoopCount = LoopCount + 1;
}
if (InputValid = true) {
cout << "IT IS VALID";
} else {
cout << "IT IS NOT VALID";
}
cin >> ANumber;
return(0);
}
=========================================================
The problem is with line:
if (ANumber[LoopCount] = ".") {
When I try to complie the code (run debug), I get an output error of:
'=': cannot convert from 'const char [2]' to 'char'
There is no context in which this coversion is possible.
Please help!
This is what I have so far:
===============================================
#include <iostream>
#include <string>
using namespace std;
float DoubleANumber(float Num) {
return (Num*2);
}
int main() {
char ANumber[30];
bool InputValid = true;
cout << "Enter a number: ";
cin.getline(ANumber,30);
int LoopCount = 0;
int Decimals = 0;
int Negitave = 0;
int CharSize = strlen(ANumber);
while (CharSize > LoopCount) {
if (ANumber[LoopCount] = ".") {
Decimals = Decimals + 1;
}
if (Decimals > 1) {
InputValid = false;
}
LoopCount = LoopCount + 1;
}
if (InputValid = true) {
cout << "IT IS VALID";
} else {
cout << "IT IS NOT VALID";
}
cin >> ANumber;
return(0);
}
=========================================================
The problem is with line:
if (ANumber[LoopCount] = ".") {
When I try to complie the code (run debug), I get an output error of:
'=': cannot convert from 'const char [2]' to 'char'
There is no context in which this coversion is possible.
Please help!