@Wo1ves1n0/

CruelUncomfortableInstance

C++

Part of my Assignment.

fork
loading
Files
  • main.cpp
main.cpp
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
/*
Computational Thinking
Assigment 3 template
"Torren Walker"
*/

#include <iostream>
using namespace std; // cout instead of std::

int main() //Main body for the code
{

  int Result=0; //Sum for where to start 0 = starting point
  int length = 0; //integer used to create the length of the array

  int smallest; // Declearing the smallest integer
  int largest;// Declearing the largest integer

  cout << "How many numbers are you checking for?: ";
  cin >> length; // the amount of numbers for the list 
  
  int MyList[length]; //Array is created using the value of length

  for (int i=0; i<length; i++) //For loop to enter values into the array
  {
  	cout << "Enter number " << i+1 << ": ";
  	cin >> MyList[i];
  }

  smallest = MyList[0];
  largest = MyList[0];

	cout << endl << "Printing Array"<< endl << "--------------" << endl; // text

  for (int i=0; i<length; i++) //For loop to enter values into the array
  {
    Result+=MyList[i]; // Adds the list that the user as given the integer for
  	cout << MyList[i] << endl; // puts the list together of what the user has entered.
  }
  cout << "--------------" << endl << "Adding your list of numbers" << endl;//Caption
  cout << "--------------" << endl;
  cout << "Total: " << Result << endl; // the total for the list added 
  cout << "--------------" << endl;
  	
    for (int i=0; i < length; i++) //Test for every value in the list
	{
		if (MyList[i] > largest) //if the current number is higher than the previous highest number
		{
			largest = MyList[i];
		}
		if (MyList[i] < smallest) //if the current number is lower
		{
			smallest = MyList[i];
		}
	}
	cout << "Largest integer: " << largest << endl;
  cout << "--------------" << endl;
	cout <<	"smallest integer: " << smallest << endl;
  cout << "--------------" << endl;

	return 0;
}