Processing input of a Char and an Int

I am writing a program and I have run into a snag when I'm trying to process the input. What I have is a program that processes a string of numbers that the user will input. Although the user can at any time stop and go back to a previous input, so I need help on how to process a char and an int in the input. Here is an example of what I'm trying to do.

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
using namespace std;

int get_input( )
{
    char input[30];
    char *end_ptr;
    int var;

    for ( ; ; )
    {
        fflush(stdout);
        fgets(input, sizeof input, stdin);        
        errno = 0;
        var = strtol(input, &end_ptr, 0);
            
        if ( end_ptr == input )
           cout << "Not a valid numeric input." << endl;
        else if ( input[0] == '\n' || ERANGE == errno )
           cout << "Not a valid number." << endl;
        else
            break;
    }
    
    return var;
}
int main( )
{
    int x, y;
    int MyTemp = 0;
    int MyValue[10] = {};

    for ( x = 1; x <= 10; x++ )
    {
        system( "cls" );
        cout << "Please enter the Temperature." << endl;
        cout << "Then enter 10 more Values." << endl << endl;
        cout << " TEMP: " << MyTemp << endl;
        for ( y = 1; y <= 10; y++ )
          cout << y << ": " << MyValue[y] << endl;
        
        if ( MyTemp == 0 ) // Temp cannot equal 0
        {
          cout << endl << "TEMP: ";
          MyTemp = get_input();
          --x;
          continue;
        }
        
        cout << endl << x << ": ";
        MyValue[x] = get_input();
    }
    
    return EXIT_SUCCESS;
}


You are first asked for a temperature, then 10 values. The part I cannot figure out is, in the get_input function I need a way to analyze the incoming input and see if it is just a numeric value, if so, "return var" just like normal so it can be entered in. But I need two commands that can be entered at any time, "Temp ###". Example...

Please enter the Temperature.
Then enter 10 more Values.

TEMP: 100
1: 1056
2: 2010
3: 1021
4: 4019
5: 0
6: 0
7: 0
8: 0
9: 0
10: 0

5: temp 109



When you at entering the 5th value, you can go back, change the value of the temperature, and continue along like nothing ever happened. I've tried a few different examples, but most ended up looking something like

 
cin >> variable1 >> variable2


And that doesn't work very well when for the most part you are entering single numbers. Any help out there please!
Why not just disallow zero or for that matter any number less than and or greater than whatever?
1
2
3
4
5
6
7
8
9
cout<<"Enter temp";
for(int i=0;i<10;i++)
{
   cin>>temp;
   if (temp<1)cout<<"not a valid temp";
   {
   cin>>temp;
   }
}

.......maybe I'm missing something?
Topic archived. No new replies allowed.