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 578711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:17:23+00:00 2026-05-13T14:17:23+00:00

I am supposed to write a program that should read from input numbers in

  • 0

I am supposed to write a program that should read from input numbers in the main() part, and then make some calculations in other bool functions. I don’t want to insert the whole arrays of the numbers and all the other parameters in the functions everytime i call them.

My question is this: Can i make somehow in c++ to read input in some variables, but in a way that other functions outside of main() will also “know” this variables and what’s inside them so i don’t have to put a lot of arguments when i call the functions ?

This is the code:

#include <iostream>
using namespace std;

inline bool del(int n)
{
    int i;
    for(i=0;i<s1;i++)
    {
        if((n % a[i]) == 0) return true;
    }
    return false;
}
inline bool ned(int n)
{
    int i;
    for(i=0;i<s2;i++)
    {
        if((n % b[i]) != 0) return true;
    }
    return false;
}
int main(void)
{
    int s1, s2, a[25], b[25];
        int m, n, i, k=0;
    bool d, nd;
    cin >> s1 >> s2 >> m >> n;
    for(i=0;i<s1;i++)
        cin >> a[i];
    for(i=0;i<s2;i++)
        cin >> b[i];
    for(i=m;i<=n;i++)
    {
        d = del(i);
        nd = ned(i);
        if(d == true && nd == true) ++k;
    }
    cout << k << endl;
    return 0;
}

int s1, s2, a[25], b[25] <- These are the vars i need to be seen by the other functions (because i use them as you can see).

I tried declaring them like global, but that didn’t work, i got errors like “was not declared in this scope” .

Thank you for the help.

  • 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-05-13T14:17:23+00:00Added an answer on May 13, 2026 at 2:17 pm

    Making variables global for this reason is bad habit. Either just pass the arrays to the functions, or make the whole thing into an object and make the arrays and functions members of the class. This is what OOP is about.

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

Sidebar

Related Questions

Java is supposed to be write once, run anywhere and it really can be,
I need to write a java script. This is supposed to validate if the
I wrote this function that's supposed to do StringPadRight("Hello", 10, "0") -> "Hello00000" .
Are we supposed to find workarounds in our web applications so that they will
I am making a small project for myself that deals with gps and some
Suppose that one has some lock based code like the following where mutexes are
Given the following code (it's supposed to write helloworld in a helloworld file, and
Almost any mature program that involves text implements double click to select the word
Would it suppose any difference regarding overhead to write an import loading all the
Suppose I am writing an application in C++ and C#. I want to write

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.