c++ program multiple declaraton error

c++ program multiple declaraton error



I am getting multiple declaration error in this c++ program


#include<iostream.h>
#include<conio.h>
void main ()
clrscr();
int a[10][10],r,q,i;
cout<<"enter how many rows and colomn you want in the matrix:";
cin>>n;
cout<<"enter the matrix n";
for(int r=0;r<n;++r)

for(int q=0;q<n;++q)

cin>>a[r][q];



for(int i=0;i<n;i++)
cout<<"n the diagnol elements are:";
cout<<a[n-i-1][i];

getch();



it is a program for finding diagnol elements in a matrix





can not reproduce, please provide Minimal, Complete, and Verifiable example
– apple apple
Aug 19 at 13:09





Wandbox example
– apple apple
Aug 19 at 13:15





Related: Why doesn't a simple “Hello World”-style program compile with Turbo C++? That is a simple example, but there are many differences between C++ and Turbo C++ that you could be tripping over. My recommendation is for you to divide and conquer. Back up your source file, then start removing pieces of the code to help you narrow down what exactly is causing the problem.
– user4581301
Aug 19 at 15:20




2 Answers
2



That's because you have already declared the r, q, i as int at line 5 as below:


r


q


i


int


int a[10][10],r,q,i;
^^^^^



While your three for loops, again re-declares for e.g. like this:


for(int r=0;r<n;++r)
^^^



So it re-declares the same variable in above case it's r, while the other for loop q and i which is not allowed.


r


q


i



Two ways to solve the problem:



a. Either you remove int from your for loop.

b. Either you remove declaration of variables used in for loop from line 5.





I believe declare variable inside for loop would not result in that error. wandbox example
– apple apple
Aug 19 at 13:12



The only issue i am seeing is, you are not declaring the variable "n" . Other than that, everything seems to be fine.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

ᵟᴈ,ᴘᵨᵷᴬ ᴳᵵᴂᴮᵇᵘᴀᴈᴵᵪᵬᴵᴬᴢᵔᵧ,ᵄᴠᴹᵔᴍᵲᵜᴫᵄᵋᴅ,ᵪᵢᵠ ᴡᵗ,ᵷᴝᵲ ᴖᴤᵡ,ᴎ,ᴚ ᵡᵪᵀ,ᴐᵉ,ᵿᴂ,ᴽᴽᵍᵟᵍᴠᵓᵯᴞᵅᵛᵢ,ᴐᴁ ᵺᴉᵸᴵᴶᵄᴪᵷ,ᴌᴠᴗᴚ,ᵟᵺᵳᴝᴉᴰ,ᵹᵥ ᵂᴴ,ᴵ,ᵉᵿ ᴕᵕ,ᴃᴡᴒᵐᴇᴳᵅᵞᴒᴝᴳᴋᴗᵢᵶᵢᵅᴣᴑᵘᵷᵾᴍᴔᴵ,ᴢᴘ,ᴮᵫᴘ,ᵳ,ᴩᵓᴞ