mardi 19 mai 2020

Random Number Array/ minimum

#include <stdlib.h>
#include <cstdlib>
#include <ctime>
using namespace std;

int minimum(int zahlen[])
{
 int minimum;
 int o = 0;
 bool prüf = false;
 while (true)
 {
     for (int p = 0; p < 20; p++)
     {
         if (o == zahlen[p])
         {
             minimum = zahlen[p];
             prüf = true;
         }
     }
     if (prüf == true)
     {
         break;
     }
     o++;
 }
 return minimum;
}

void main()
{
 srand(clock());
 int array[20];
 for (int i = 0; i < 20; i++)
 {
     array[i] = rand();
 }

 //Minimum
 cout << "Die kleinste Zufallszahl die erstellt wurde ist die: " << minimum(array) << endl;

 system("PAUSE");
}

Hi, I have to create a 20 numbers long random array and check for the smallest number. I know my code is probably not the best method to use for this problem but I am just always getting 371, 374, 202 or 208 as result. Never something else. Is there a problem I don't see?




Aucun commentaire:

Enregistrer un commentaire