help

i am having difficulties doing this program. i dont know how to search for the value 80.





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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <cstdlib> 
#include <ctime> 
#include <iostream>

using namespace std;

class SortArray
{
    public:
            int randomArray[];
			int find(int randomArray[], int len, int seek);
            void MoveUp();
            void OutputNumbers();
            void GenerateRandomNumbers();
};

void main(void) 
{ 

 SortArray cSort;
    srand(time(0));

    ///Gets ten random numbers from 1 through 100
    cSort.GenerateRandomNumbers();
    cout<<"The numbers before they are sorted"<<endl;

    ///Outputs The Numbers Before Sorting Them
    cSort.OutputNumbers();
    cout<<endl<<endl;

	cSort.find();

    ///Sorts Numbers
    cSort.MoveUp();
    cout<<"The numbers after they have been sorted"<<endl;

    ///Outputs Number After They Have Been Sorted
    cSort.OutputNumbers();

    cout<<endl;
	system("pause");
	
 }

void SortArray::MoveUp()
{
    int placeHolder;

    for(int g=1; g<51; g++)
    {
        ///Since I am comparing array positions next to eachother I initialize the variable numberAbove to one higher than g
        for(int numberAbove=g+1; numberAbove<51; numberAbove++)
        {
            ///If the number lower in array position is higher in value than number higher in array position...proceed to switch
            if(randomArray[g] > randomArray[numberAbove])
            {
                ///Puts Lesser Value Into A Placeholder
                placeHolder = randomArray[numberAbove];

                ///Puts Bigger Value In Upper Position
                randomArray[numberAbove] = randomArray[g];

                ///Puts Lesser Value in Lower Position
                randomArray[g] = placeHolder;
            }
        }
    }
}

void SortArray::GenerateRandomNumbers()
{
    for(int i=1; i<51; i++)
    {
        randomArray[i] = (rand() % (100 - 60 + 1)) + 60;
    }
}

void SortArray::OutputNumbers()
{
    for(int j=1; j<51; j++)
    {
        cout<<randomArray[j]<<endl;
    }
}

int SortArray::find(int randomArray[], int len, int seek)
{
    for (int i = 0; i < 50; ++i)
    {
        if (randomArray[i] == 80) 
		return i;
    }
    return -1;
}
Last edited on
Topic archived. No new replies allowed.