Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cctype>
- using namespace std;
- void readAndClean (int& n);
- void newLine();
- void readAndClean (int& n)
- {
- const int ARRAY_SIZE = 6;
- char digitString[ARRAY_SIZE];
- char next;
- cin.get(next);
- int index = 0;
- while (next != '\n')
- {
- if ((isdigit(next)) && (index < ARRAY_SIZE - 1))
- {
- digitString[index] = next;
- index++;
- }
- cin.get(next);
- }
- digitString[index] = '\0';
- n = atoi(digitString);
- }
- void newLine()
- {
- char symbol;
- do
- {
- cin.get(symbol);
- }
- while (symbol != '\n');
- }
- int main()
- {
- int n;
- char ans;
- do
- {
- cout<<"Enter an integer and press Return: ";
- readAndClean(n);
- cout <<"That string converts to the integer " << n <<endl;
- cout <<"Again? (yes/no): ";
- cin>> ans;
- newLine();
- }
- while ( (ans != 'n') && (ans != 'N') );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement