Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include<iostream>
#include<vector>
using namespace std;
int main()
{
cout << "example";
cout << " 1 , 2 , -7 , -6 , 3 ";
cout << " the next smallest is -5";
cout << "another example";
cout << " -45 , -1000 , -1 , -2 ";
cout << " the smallest is -999";
return 0;
}

What I have tried:

#include<iostream>
#include<cmath>
#include<ctime>
#include<iomanip>
#include<string>
#include<vector>
using namespace std;
int main()
{
   vector<int> choosen_numbers;
   unsigned int i;
   int amount_of_numbers;
   int storage_memory;
   int minimum;
   int x;
   cout <<"How many numbers?";
   cout <<endl;
   cin >> amount_of_numbers;
   choosen_numbers.resize(amount_of_numbers);
   cout << "Please enter the numbers";
   storage_memory = 0;
   for (i = 0 ; i < choosen_numbers.size() ; ++i)
   {
      cin >> choosen_numbers.at(i);
      if (choosen_numbers.at(i) >= 0 || choosen_numbers.at(i) < 0)
      {
         storage_memory = i;
      }
   }
   minimum = choosen_numbers.at(0);
   for ( i = 0 ; i < amount_of_numbers ; ++i)
   {
      if(minimum > choosen_numbers.at(i))
      {
         minimum = choosen_numbers.at(i);
      }
   }
   cout <<"The smallest missing number is ";
   for ( i = 0 ; i <  amount_of_numbers ; ++i)
   {
      minimum = 1 + minimum;
      for (int j = 0 ; j < amount_of_numbers ; ++j)
      {
         if(minimum == choosen_numbers.at(j))
         {
            cout << choosen_numbers.at(j) + 1;
         }
      }
   }
   return 0 ;
}
Posted
Comments
Rick York 23-Oct-21 14:26pm    
What is your question?
gggustafson 23-Oct-21 14:49pm    
You're setting your minimum incorrectly. I'd initialize it to INT_MAX. Then the test would become
    if ( choosen_numbers.at ( i ) < minimum )
      {
      minimum = choosen_numbers.at(i);
      }


FYI "choosen" should be spelled "chosen".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900