finding smallest& largest in array doesn't work

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
// level 3 minsta storsta.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <time.h>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
	{
	int minst,storst,i,slump[10];
	
	srand(time(NULL));
	for (i=0;i<10;i++)
	{
		slump[i]=rand()% 10 + 1;
		cout<<slump[i]<<endl; // just there so I can check the biggest and the smallest number to compare if they match my biggest and smallest ints
	}
	minst=slump[0];
	
	for (i=0;i<10;i++)
		{
				if (minst>slump[i])
		{
			minst=slump[i];
		}
	}
	storst=slump[0];
	for (i=0;i<10;i++)
	{
		if (storst<slump[0])
		{
			storst=slump[i];
		}
	}


	


	cout<<"Det minsta v\x84rdet \x84r "<<minst<<" och det storsta v\x84rdet \x84r "<<storst<<endl;
getch();

}

		

I get the error that both smallest and biggest integers show the same value although that's not what I want. Please help!
Last edited on
if (storst<slump[0])

Should be i not 0.
doh! thanks!
i'm sorry for this noobish question.. but how do I do if I want the option to re-run the program?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <cstdlib>
#include <iostream>

int main()
{
    char repeat = 'Y';

    while (repeat == 'Y')
    {
        // your program goes here

        std::cout << "Want to run again? Y = Yes, whatever else = No\n> ";
        // std::cout.flush(); // just in case the message doesn't show for you
        std::cin >> repeat;
    }

    system("PAUSE");
    return EXIT_SUCCESS;
}
Topic archived. No new replies allowed.