-2

I'm 10th grade student, only 2 weeks of coding. I have a homework to fix this code if not working from the book with the title "Finding the smallest element of a vector". I've been stuck here over 5 days, and tomorrow is my due date.

    #include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    int i, T[10], int min;
    for (i = 10; i < 10; i = i + 1)
        cin >> T[i];
    min = T[0];

    for (i = 1; i < 10; i++)
        if (T[i] < min)
            min = T[i];

    cout << "Min= " << min;
    return 0;
} 

What should I change in order to work? Thank you.

2 Answers2

1

There were two lines wrong: int i, T[10], int min; and for (i = 10; i < 10; i = i + 1). Here is a working link.

#include <iostream>
using namespace std;

int main()
{
    int i, T[10], min;
    for (i = 0; i < 10; i = i + 1)
        cin >> T[i];
    min = T[0];
    for (i = 1; i < 10; i++)
        if (T[i] < min)
            min = T[i];
    cout << "Min = " << min;
    return 0;
} 
brc-dd
  • 10,788
  • 3
  • 47
  • 67
0

In the first for you should go from i = 0, not i = 10.

dasfex
  • 1,148
  • 2
  • 12
  • 30
  • I just tried, the compiler just says "compiling" and then nothing... [the code in compiler](http://cpp.sh/7wdh7) – Deivid Miço Apr 28 '20 at 13:35
  • 1
    It's waiting for *you* to say something. That's what `cin` does. – cigien Apr 28 '20 at 13:37
  • I typed, it stood froze and didn't do anything – Deivid Miço Apr 28 '20 at 13:45
  • @DeividMiço just press on the run and it will say program running. A cursor would be blinking in execution panel. Where you have to enter 10 numbers and hit enter. Enter these for example: `5 6 2 8 1 0 9 3 7 3`. See this video: https://imgur.com/a/Czdo4wV. – brc-dd Apr 28 '20 at 13:49