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

  • SEARCH
  • Home
  • 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 8103295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:30:17+00:00 2026-06-05T23:30:17+00:00

I’m new to C++ and trying to make two simple functions, but something goes

  • 0

I’m new to C++ and trying to make two simple functions, but something goes wrong.

I am trying to do the following:

1.Function for input some data.
2.Function to show what data is input.

I just want to make it simple. The code I wrote so far is:

#include <iostream>
void masiv()
{
  int x[10];
  int n, i;
  int min;
  int max=0, imax=0, imin;

  cout << "Enter the number of elements: ";
  cin >> n;

  for(i=0; i < n; i++)
  {
      cout << "Input value for x["<<i<<"]=";
      cin >> x[i];

  if (min > x[i])
  {
      min = x [i];
      imin = i;
  }

  if (max < x[i])
  {
     max = x[i];
     imax = i;
  }
}
void rezult()
{
  cout << "the smallest value on is xthe biggest value on is x["<<imin<<"]=" << min <<endl;
  cout << "nai golqmata stoinost e na x["<<imax<<"]=" << max <<endl;
}
void main()
{
  masiv();
  rezult();
}

I got bunch of errors. I know this is poor code but as I mentioned I’m just starting.
Thanks

P.s. Sorry for my English

Edit: Working with this code.

#include <iostream>
using namespace std;

void masiv(int& min, int&max)
{
 int x[10];
 int n;
 int i;
 int imin, imax;
 cout << "Enter the number of elements: ";
 cin >> n;
 for(i=0; i < n; i++)
 {
  cout << "Input value for x["<<i<<"]=";
  cin >> x[i];
  if(min > x[i])
  {
    min = x [i];
    imin = i;
  }
  if(max < x[i])
  {
    max = x[i];
    imax = i;
  }
 }
}

 void rezult(int min, int max)
{
 cout << "the smallest value on is x= " << min << endl;
 cout << "the biggest value on is x= " << max << endl;
 system ("pause");
}

int main(int argc, char** argv)
{
 int min = 999999; 
 int max = -999999;
 masiv(min,max);
 rezult(min,max);
 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-05T23:30:20+00:00Added an answer on June 5, 2026 at 11:30 pm

    The min variable is never initialized, it should be initialized to a large value.

    You declare an array int x[10]; but later you let user enter the number of values cin>>n without checking if it is larger than 10 or negative. This could cause an issue.

    The max and min are declared only in the function masiv() they cannot be reached outside the function. If you want to make them accessible you could for instance pass them to the function instead of declaring them inside the function:

    void masiv(int& min, int&max) // pass by reference
    {...}
    
    void rezult(int min, int max)
    {...}
    
    int main(int argc, char** argv) // proper main prototype
    {
       int min = 999999; 
       int max = -999999;
       masiv(min,max);
       rezult(min,max);
       return 0;
    }
    

    edit : and add using namespace std; at start of file

    #include <iostream>
    using namespace std;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when I
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

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.