Search Results

Search found 1 results on 1 pages for 'user1801781'.

Page 1/1 | 1 

  • This program isn't asking for the predetermined 5 numbers from the array?

    - by user1801781
    Okay, so this question is difficult to state. I'm a beginner at C++, and I rarely run into problems with these simple assignments, but something is majorly wrong here and I cannot identify it. I've been trying for hours. This program is supposed to read 5 numbers from an array that the user enters, and then print the largest one. (I know it's easier to just write a for-loop, but our professor wanted us to call a function). The only problem is that instead of asking for 5 numbers, it asks for 2. It works other than that, I JUST NEED IT TO ASK FOR 5 NUMBERS. haha. Your input would be greatly appreciated. I aspire to be a programmer one day, so don't be afraid to go harsh on me. #include <iostream> using namespace std; int largest_number(int score[], int max) { for (int i=1; i<5; i++) { cin >> score[i]; if(score[i] > max) max=score[i]; return (max); } } int main () { int score[5], max, z; cout << "Enter 5 numbers: " <<endl; cin >> score[0]; max = score[0]; z = largest_number(score, max); cout << "The largest number is: " << z <<endl; system("pause"); return 0; }

    Read the article

1