Question

In: Computer Science

C++ I have to create printArray, but I have the error " error C2065: 'ar': undeclared...

C++

I have to create printArray, but I have the error " error C2065: 'ar': undeclared identifier". Just need a little help.

#include
#include
#include

using namespace std;

void fillArray(int a[], int size);
void printArray(int a[], int size);


int main()
{
   int ar[10];

   fillArray(ar, 10);
   printArray(ar, 10);

   return 0;
}
void fillArray(int a[], int size)
{
   for(int i = 0; i < 10; i++)
       a[i] = rand() % 10 + 1;
}
void printArray(int a[], int size)
{
   for (int i = 0; i < 10; i++)
       cout << ar[i];
}

Solutions

Expert Solution

Coming to your code in that function you passing an array named a[] not ar[] array so you got ar[] is not defined in the scope

so you make change of ar[] to a[] or pass ar[] in function definition in order to run code successfully

here i made ar[] as a[] now the code is running without an error

Here is the modified code

#include <stdio.h>
#include <cstdlib>
#include <iostream>
using namespace std;

void fillArray(int a[], int size);
void printArray(int a[], int size);


int main()
{
int ar[10];

fillArray(ar, 10);
printArray(ar, 10);

return 0;
}
void fillArray(int a[], int size)
{
for(int i = 0; i < 10; i++)
a[i] = rand() % 10 + 1;
}
void printArray(int a[], int size)
{
for (int i = 0; i < 10; i++)
cout << a[i] << "\n" ;
}

Output

Any queries regarding this comment please


Related Solutions

C++ - Almost done, I have a problem with read access violation error. This is the...
C++ - Almost done, I have a problem with read access violation error. This is the link to my assignment first part: https://pastebin.com/yvcvdqLY second part: https://pastebin.com/vY7MK1Bf, My header file: https://pastebin.com/pcJnctgu My .cpp file: https://pastebin.com/9jAfP9u8 My source file: https://pastebin.com/kFsidY2k
Syntax error in C. I am not familiar with C at all and I keep getting...
Syntax error in C. I am not familiar with C at all and I keep getting this one error "c error expected identifier or '(' before } token" Please show me where I made the error. The error is said to be on the very last line, so the very last bracket #include #include #include #include   int main(int argc, char*_argv[]) {     int input;     if (argc < 2)     {         input = promptUserInput();     }     else     {         input = (int)strtol(_argv[1],NULL, 10);     }     printResult(input);...
I have a error code, for my C++ class, using Putty include <iostream> using namespace std;...
I have a error code, for my C++ class, using Putty include <iostream> using namespace std; int main() { char answer; char grade; cout << "Are you taking a class (enter y, Y, N or N): " << endl; cin >> answer; if (answer == 'N' || 'n'); { cout << "Thanks for using the system" << endl; } else if (answer == 'Y' || 'y'); { cout << "Enter a letter grade (A, B, C, D, or F): "...
I have to create a program in C++ where a user can enter as many numbers...
I have to create a program in C++ where a user can enter as many numbers as they want (they predetermine the number of values to be inputted) and then the program can echo that input back to the user and then determine if the numbers were even, odd, or a zero and it outputs how many of each were found. This is to be down with four void functions and no arrays. The program initializes the variables zero, odds,...
Hello I have this error in the code, I do not know how to fix it....
Hello I have this error in the code, I do not know how to fix it. It is written in C++ using a Eclipse IDE Error: libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string bus.h =========== #pragma once #include using namespace std; class Bus { private:    string BusId; // bus ID    string Manufacturer; // manufacturer of the bus    int BusCapacity; // bus capacity    int Mileage; // mileage of bus    char Status; // current status...
Whenever I am attempting to write a simple program on C++ I get an error message...
Whenever I am attempting to write a simple program on C++ I get an error message that reads "cout was not declared in this scope". Literally every time. This has become frustrating because I have even written my code the exact same way as some of my classmates who got theirs to compile and run with no sign of this error at all, and yet min gives this answer. I will leave an example of a code where this error...
The rate consant for the reaction I+I+Ar---->I2+Ar is 0.59 x 1016 cm6mol-2s-1 at 293K. What is...
The rate consant for the reaction I+I+Ar---->I2+Ar is 0.59 x 1016 cm6mol-2s-1 at 293K. What is the half-life of I is [I]o= 2 x 10-5 mol L-1 and [Ar]= 5 x 10-3 mol L-1?
7.  Is it Type I and II error? Explain why?? a.  Many medical studies have a high error...
7.  Is it Type I and II error? Explain why?? a.  Many medical studies have a high error rate because they are not able to use large sample for Medical diagnostic procedure such as Mammogram. b. When a radiologist interprets a mammogram, is a “false positive” predicting that a woman has a breast cancer when actually she does not! c. c. Remdesivir Drug &  Clincial trials - Dr. Fauci Infectious specialist claims at p =0.31 could shorten the time to recover from the...
Im getting an error on the Player.h class. Error reads expected initializer before player. I have...
Im getting an error on the Player.h class. Error reads expected initializer before player. I have put a comment by the line with the error. sample out put is Welcome to Rock Paper Scissors You played: paper Computer played: paper It's a tie Player.h #include<string> using namespace std; class Player{    private:        int play;//variable        public:    string getPlay();//variables    void setPlay(string play);    void setPlay(int play); } string Player = getPlay(){//error    if(this.play == 1){   ...
hello i have question in c++ language Q1: create a class called RightTriangleShape, and it has...
hello i have question in c++ language Q1: create a class called RightTriangleShape, and it has data member called height which initialized to 3 by the constructor of the class. It has also the following function members: Void setHeight() to read, and set the height. Void getHeight() to print the value of height. void leftBottom_RTraingle(), prints shape a void leftTop_RTraingle(), prints shape b. void RightTop_RTraingle(), prints shape c. void RigtBottom_RTraingle(), prints shape d. The functions from 3 to 6 have...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT