Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8925121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:36:48+00:00 2026-06-15T07:36:48+00:00

Okay, so this question is difficult to state. I’m a beginner at C++, and

  • 0

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:36:50+00:00Added an answer on June 15, 2026 at 7:36 am
    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); //whoops! it's inside the for loop
        }
    }
    
    • You made a mistake by putting your return inside of the for loop,
      this means no matter what you’re only entering score[1] because the function will return max afterwards.

    Remove the return inside your for loop and put it at the end of the function, and you should be fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay this may be a simple question but I have yet to come with
Okay this may seem too simple of a question but I've wasted enough time
Okay this question is very simple: I have a facebook page, and a website.
Okay this is definitely a n00b question but here goes. The way I understand
Okay this is definitley an easy question and a stupid one but since I
Okay I wasn't really sure how to word this question, but basically what I
okay so this is probably a soft pitch question for sombody, but I want
Okay I hate to ask this question ... but here goes. I am writing
Okay, I know this question have been asked plenty of times already, but I
1. Okay this is probably lame question, but I haven't found good result searching

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.