a real challenge this time

Reply

Join Date: Nov 2005
Posts: 31
Reputation: sahil_logic is an unknown quantity at this point 
Solved Threads: 0
sahil_logic sahil_logic is offline Offline
Light Poster

a real challenge this time

 
0
  #1
Nov 21st, 2005
//square matrix
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int main()
{ void diagsum(int a[10][10],int n);
void rowsum (int a[10][10],int n);
void colsum (int a[10][10],int n);
int a[10][10];
int n,opt;
cout<<" enter the size of matrix (say 4 for 4/4etc..) ";
cin>>n;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{cin>>a[i][j];
}
}
for(int k =0;k<n;k++)
{
for(int l=0;l<n;l++)
{cout<<a[k][l]<<"\t";
}
cout<<endl;
}
cout<< " enter 1 for diag sum , 2 for row sum , 3 for column sum ";
cin>>opt;
switch(opt)
{
case 1: diagsum(int a,int n);/* the compiler is showing error from here .it says - primary expression required before int */
getch();
break;
case 2: rowsum(int a, int n);
getch();
break;
case 3: colsum(int a, int n);
getch();
break;
default: cout<<" wrong option ";

}
}

void diagsum(int a[10][10],int n)
{
int diag1=0,diag2=0;
for(int i=0;i<n;i++)
{
for (j=0;j<n;j++)
{
if(i==j)
{
diag1+=a[i][j];
}
if(i+j==n-1)
diag2+=a[i][j];

}
cout<<" diagonal 1 = "<<diag1;
cout<<"\n diagonal 2 = "<<diag2;

}

void rowsum (int a[10][10],int n)
{
int row,sum;
for(int i=0;i<n;i++)
{
for int j=0;j<n;j++)
{
sum+=a[i][j];

}
cout<<" sum of row "<<n<<" is "<<sum;
}
}
void colsum (int a[10][10],int n)
{
int col,sum;
for(int i=0;i<n;i++)
{
for int j=0;j<n;j++)
{
sum+=a[j][i];

}
cout<<" column of column "<<n<<" is "<<sum;
}
}
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,671
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 261
Lerner Lerner is offline Offline
Posting Virtuoso

Re: a real challenge this time

 
0
  #2
Nov 21st, 2005
Dont declare functions inside of other functions (in this case inside main(), and when you call a function and need to pass it arguments, don't indicate the argument type, just the argument name or an objects address (if the function is expecting a pointer and what you have is an object).
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: a real challenge this time

 
0
  #3
Nov 21st, 2005
So what's your question? I see nothing but a bunch of code in need of a few band aids, but no question.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 31
Reputation: sahil_logic is an unknown quantity at this point 
Solved Threads: 0
sahil_logic sahil_logic is offline Offline
Light Poster

Re: a real challenge this time

 
0
  #4
Nov 22nd, 2005
wat does it mean by primary expression required before int
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 31
Reputation: sahil_logic is an unknown quantity at this point 
Solved Threads: 0
sahil_logic sahil_logic is offline Offline
Light Poster

Re: a real challenge this time

 
0
  #5
Nov 22nd, 2005
why not to declare functions inside main??? it is not a prob as far as i know , i have made a quite a few prog doing the same
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: a real challenge this time

 
0
  #6
Nov 22nd, 2005
In switch case u r declaring a prototype...it should be a function call there...from next time use code tags ....and instead of arguing with people in the forum u should accept ur mistakes....try learning things....in your previous posts u said u downloaded DEV....i don't think u r using that
Note: Everyone is not gonna post corrected codes for u here always
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: a real challenge this time

 
0
  #7
Nov 25th, 2005
why not to declare functions inside main??? it is not a prob as far as i know , i have made a quite a few prog doing the same
You're right, you can put function prototypes in a block. But then they're only visible to the end of the block.
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC