Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int& replace(string& line, char from, char to) {
- int count = 0, lenght = line.length();
- for (int i = 0; i < lenght; i++) {
- if (line[i] == from) {
- line[i] = to;
- count++;
- }
- }
- return count;
- }
- int main() {
- string text = "";
- int lenght, i;
- bool isNumber = true, containPoint = false;
- setlocale(LC_ALL, "Russian");
- cout << "Введите вещественное число: ";
- getline(cin, text);
- replace(text, '.', ','); // '.' -> ','
- lenght = text.length();
- if (lenght == 0)
- isNumber = false;
- isNumber = isNumber && (isdigit(text[0]) || text[0] == '+' || text[0] == '-' || text[0] == ',');
- containPoint == isNumber && text[0] == ',';
- for (i = 1; i < lenght && isNumber; i++) {
- isNumber = isdigit(text[i]) || text[i] == ',';
- if (text[i] == ',') {
- isNumber = !containPoint && isNumber;
- containPoint = true;
- }
- }
- cout << (isNumber ? "Является вещ. числом!" : "Не является вещ. числом!") << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement