Link to home
Start Free TrialLog in
Avatar of tedschnieders
tedschnieders

asked on

need help with a loop and aray

i neeed help writting a program that asks the user to input 10 integers tests to make sure it is an integer and assorts it in assending order if they ener a invalid number ask them to reenter it

i need help with this and it is urgent so anyone that can help me with this i would gatelly appreciate it

maybe some hints or some code on how i should go about this

thanks
ted
Avatar of jkr
jkr
Flag of Germany image

#include <list>
#include <iostream>
using namespace std;

int ReadInt () {

    int n;
    string str;
      while (1) {

        cout << "Enter an integer: " << endl;

          getline(cin,str);

        char* pc;
            n = (int) strtol(str.c_str(),&pc,10);

            if (*pc) { // conversion error, not a valid int

                cout << "Invalid number" << endl;

            } else break; // terminate loop
      }

      return n;
}

int main () {

    list<int> lst;
    int n;

      for ( int i = 0; i < 10; ++i) {

          n = ReadInt ();

            lst.push_back(n);
      }

      lst.sort();

      for ( list<int>::iterator it = lst.begin(); it != lst.end; ++it) {

          cout << *it << endl;
      }
}
Avatar of tedschnieders
tedschnieders

ASKER

thank you for responding so quickly

i want them to enter one number at a time and store them in a array 0 - 9
then i want to spit them back out in acccending orplease help me
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial