an Amateur programer 1

Hi everyone

I have 2 problems : 1)I'm new to programming . 2)I can't good speak English .
so I'll be appreciated if you answer me in a simple simple simple type .


Q1)
our professor told us to utilize borland cpp 5 , and I work with windows7 , but after 3 months of using bc5 I'm going crazy becuz I don't know how to compile my programs line by line so it's too hard to find my semantic errors . is there a good thing to download to solve this problem ? if yes plz give me the link .
//end Q1


Q2)
in deitel book there is an example in which an int variable is declared , but the user enters char inputs :
int grade ; //declaration
...
cin >> grade ; //user will enter a or b or ...
...
but if I enter a char instead of an int value , my program will be suddenly ended and the output is closed . what can I do ? I really need to know this for one my homeworks .
//end Q2


Q3)
can somebody plz tell me what's wrong with the program below ?
my problems are that :
1-3)I know that sending an array to a function is call by reference so all of the changes occurred in the function should be applied to the first array but this won't happen in my program .
2-3)if the function "star()" was of void type , the program did nothing after printing the shape , but when I changed
void star()
to
int star()
{ ...
return 0 ; }
this problem was solved . why ?

//this is the program :

int star()
{
for( int i = 1 ; i <= 3 ; i++ )
{
for( int j = 3 - i ; j >= 0 ; j-- )
cout << " " ;
for( int j = 2*i - 1 ; j >= 1 ; j-- )
cout << "*" ;
cout << "\n" ;
}
for( int i = 2 ; i >= 1 ; i-- )
{
for( int j = i-3 ; j <= 0 ; j++ )
cout << " " ;
for( int j = 2*i - 1 ; j > 0 ; j-- )
cout << "*" ;
cout << "\n" ;
}
return 0 ;
}//end func star


//this function skips the column "jump" and the row "iump" of the resource //matrix which is 3*3 and makes a 2*2 matrix with other elements :
void Remove( int iump , int jump , int matrix[][3] , int result[][2] )
{
int ri , rj ,//i or j of the result matrix
i , j ;

for( ri = 0 , i = 0 ; i < 3 ; i++ , ri++ )
{
if( i == iump )
i++ ;

for( rj = 0 , j = 0 ; j < 3 ; j++ , rj++ )
if( j == jump )
j++ ; //end j

result[ri][rj] = matrix[i][j] ;
}//end loop

}//end func remove


//replaces one of the columnn of resource matrix (related to x or y or z )
//with the elements of the 1*3 matrix named b
void Replace( int b[] , int matrix[][3] , int x , int Ax[][3] )
{
for( int i = 0 ; i < 3 ; i++ )
for( int j = 0 ; j < 3 ; j++ )
{
if( j != x )
Ax[i][j] = matrix[i][j] ;
else
Ax[i][j] = b[i] ;
cout << 'r' << Ax[i][j] << ' ' ;//trace the process
}//

}//end fuc replace


//save data in a file
void save( int x , int y , int z )
{
fstream myfile("D:\\exam.txt", ios :: app ) ;

myfile << "\nx = " << x << " y = " << y << " z = " << z ;

}//end func save


//manage the process of determinant
int Det( int matrix[][3] )
{
int joint[3] ,
sign[3] ,
A[3][2][2] = {0} ,
result = 0 ;


for( int j = 0 ; j < 3 ; j++ )
{
Remove( 0 , j , matrix , A[j] ) ;
cout << 'd' << A[j][0][0] << ' ' ;
sign[j] = pow( -1 , j+0 ) ;
joint[j] = sign[j]*A[j][0][j] ;
}//end for removement


for( int i = 0 ; i < 3 ; i++ )
{
joint[i] *= ( A[i][0][0]*A[i][1][1] - A[i][0][1]*A[i][1][0] ) ;
result += joint[i] ;
}

return result ;
}//end func det

int main()
{
//struct data { char majhul[3][3] ; int adad[3][3] ; } ;
//I wanted to work with struction but it went wrong so I abandoned that idea
char multiuse = 'y' ,
xyz[3][3] ;
int i , j ,
b[3] ,
A[3][3][3] ,
matrix[3][3] ,
coefficients[3][3] ,
result[3] ,
det ;

do
{
star() ;
cout << "\nEnter three equivalents with x and y and z :\n" ;

//read the equivalents
for( i = 0 ; i < 3 ; i++ )
{
for( j = 0 ; j < 3 ; j++ )
{
cin >> coefficients[i][j] >> xyz[i][j] ;
cout << coefficients[i][j] << xyz[i][j] << "\n" ;//trace the process
}//end for j
cin >> multiuse >> b[i] ;
cout << "\n" << multiuse << b[i] ;
}//end for i
//end reading

for( i = 0 ; i < 3 ; i++ )
for( j = 0 ; j < 3 ; j++ )
{
switch( xyz[i][j] )
{
case 'x' :
matrix[i][0] = coefficients[i][j] ;
break ;

case 'y' :
matrix[i][1] = coefficients[i][j] ;
break ;

case 'z' :
matrix[i][2] = coefficients[i][j] ;
break ;
}//end switch
}//end assignment

det = Det( matrix ) ;
cout << det ;//trace the process

for( j = 0 ; j < 3 ; j++ )
{
Replace( b , matrix , j , A[j] ) ;
result[j] = Det( A[j] ) / det ;
}//end for

save( result[0] , result[1] , result[2] ) ;

cout << "\nx = " << result[0] << " y = " << result[1]
<< " z = " << result[2] ;

//for( j = 0 ; j < 3 ; j++ )
cout << "\nWould you like to do this process with another matrix ?"
<< "\npress 'y' , otherwise press any key to quit the program . " ;
cin >> multiuse ;

}while( multiuse == 'y' ) ;

getch() ;
return 0 ;
}//end main
//end Q3

I have another Question too which I have to send in another post ...
Hi there,

Q1) Most compilers will show you where the error occurred, but sometimes it is not obvious at first. I don't have experience with borland though, if I were using windows I would probably use "MingW", which is a port of the GCC. What program do you use to write your code in? Some programs can format the output of the compiler so that it is a bit more readable.

Q2) If you are sure that you will always get a char instead of an int, just change int grade; to char grade;. If both can happen, you will have to check the failstate of cin, but you probably don't need to.

Q3) I would advise you to make a separate topic for this question, try and describe clearly what the program needs to do, what output you expect, and what ouput you are getting instead. If you get compiler errors, provide those as well. Don't forget to wrap the code in code tags: [code] code here [/code]

All the best,
NwN
thank you my problems were solved
Topic archived. No new replies allowed.