I have to minus the smallest number in an array from the rest of the numbers in the array with the smallest number to 0

Basically im doing a menu where i create an array and a list of options comes up and each option caries out a different function to do with the array i.e option 1 would be to display the largest number in the array

I am having trouble with minusing the smallest number in the array away from the rest of the numbers in the array. It works but for some reason it only minuses the smallest number from the numbers that come AFTER the smallest number in the array for example the numbers in a 5 number array are
5
6
2
5
6
the output would be
0
1
0
3
4
it seems to minus the first number away from the numbers BEFORE the smallest number and the smallest number away from the numbers AFTER the smallest number.

This is my code if you guys could tell me what im doing wrong it would be great im sure its something small.

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
  int big, small, small1, value, count = 0;
	int list[12]; //integers will be the elements in the array 
	int option;
	int sum = 0;
	int sum1 = 0;
	//populating the array
	cout << "Enter 12 numbers : ";
	for (int i = 0; i < 12; i++)
	{

		cin >> list[i]; //for loop increments i 12 times so the user enters 12 digits 

	}

	big = small = small1 = list[0]; //assigns element to highest/lowest value 

	do //do while loop while option isnt 99 as option 99 exits the menu
	{
		//various options in the menu
		cout << "\t\tMenu\n";
		cout << "\t0.Display\n"; //displays all numbers in the array
		cout << "\t1.Total\n"; //Adds all the numbers in the array together
		cout << "\t2.Average\n"; //finds the average of all the numbers in the array
		cout << "\t3.Largest\n"; //finds the largest number in the array
		cout << "\t4.Smallest\n"; //finds the smallest number in the array
		cout << "\t5.Occurance of value\n"; //shows the amount of times a value occurs in an array
		cout << "\t6.Multiply values by number entred\n"; //multiplies each number by value entered 
		cout << "\t7.Reverse array\n"; //outputs the array in reverse order 
		cout << "\t8.Minus smallest number in array from the 12 numbers /n";
		cout << "\t99.Exit\n"; //exits the menu
		cout << "\t\t Option ? ";
		cin >> option; //user enters which option they want to choose 


		switch (option) //switch statement, each case is the option entered by the user 
		{
		case 0:

			cout << "Contents\n"; //displays the integers in the array


			for (int i = 0; i < 12; i++) //This for loop is in all the cases so that list[i] is identified
			{                            //user does not have to enter the numbers again as list[i] has already been populated

				cout << list[i] << endl; //outputing all the integers in list[i] to the screen

			}
			break; //break loops back up to the menu of options after the case is finished

		

		case 8:

			for (int i = 0; i < 12; i++)
			{
				if (list[i] < small1)
					//again the smallest value is found
				{

					small1 = list[i];

					 //stored in small
			
				}

				 //the elements in the array are then minused by small and stored back into the array
				list[i] = list[i] - small1;
				 //new elements in the array are outputed to the screen
				cout << list[i] << endl;
			}
			break;

		case 99: //exits the menu as the do while loop stays in the loop for everything except 99
			cout << "You are now exiting the menu, Goodbye.\n";
			break;

		default: //any number that isnt a case in the switch statment is an invalid option.
			cout << "Invalid option\n";
			break;
		}

	} while (option != 99);

	return 0;


Its only case 8 of the switch statement is the one im having trouble with, i got rid of the rest of the cases because there irrelevant that's why there's a load of integers and stuff at the top
closed account (48T7M4Gy)
You need another loop after you have the smallest. That loop goes thought each element and subtracts the smallest from it.

1
2
3
4
5
for etc ...
{
   list[i] = list[i] - small1;
   cout << etc
}


closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/180715/
Topic archived. No new replies allowed.