• 08-04-2004
hunterdude
I have two variables:
double a;
double b;

I can display them...
std::cout<<a<<" "<<b;

and I can display their sum, difference, and product. But when I make a new variable...
double c = a/b;

the program just stops when I try to display it. Can someone please tell me why this is?

Thanks
• 08-04-2004
quzah
Well, generally you'll want to actually post the code you're having problems with.
Code:

```#include <iostream> int main( ) {         double a, b, c;         a = 1.1;         b = 2.2;         c = a / b;         std::cout << "a is " << a                   << " and b is " << b                   << " and c is " << c                   << "\n";         return 0; } /* a is 1.1 and b is 2.2 and c is 0.5 */ ```
Quzah.
• 08-04-2004
hunterdude
Quote:

Well, generally you'll want to actually post the code you're having problems with.
That's what I was afraid of. I was hoping someone had experienced this before and could give a quick answer. Well, here it goes.

It is part of a matrix class I am trying to make. One of the functions I am having problems with is one which multiplies a row by a number.

Code:

```void Matrix::MultiplyRow(int Row,double Factor) {         for(int u=1;u<=j;u++) {                 ChangeElement(Row,u,Factor*GetElement(Row,u));         } }```
It works fine most of the time but fails if I try something like this:
matrix.MultiplyRow(1,1.0/b.GetElement(1,1));

I can display the denominator like this:
std::cout<<b.GetElement(1,1);

but this doesn't work:
std::cout<<1.0/b.GetElement(1,1);

Here are the ChangeElement() and GetElement() functions:
Code:

```double GetElement(int row,int column) { return thematrix[column-1][row-1]; } void ChangeElement(int row,int column,double value) { thematrix[column-1][row-1]=value; }```
Thanks,
hunterdude
• 08-04-2004
quzah
Really? It works for me:
Code:

```#include <iostream> class Foo {         private:                 double matrix[5][5];         public:                 double const GetElement( const int row, const int col )                 {                         return matrix[row][col];                 }                 void ChangeElement( const int row, const int col, double d )                 {                         matrix[row][col] = d;                 }                 Foo()                 {                         int a, b;                         for( a = 0; a < 5; a++ )                                 for( b = 0; b < 5; b++ )                                         matrix[a][b] = a * 5 + b;                 } }; int main( ) {         Foo f;         std::cout << 1.0 / f.GetElement( 1, 2 );         return 0; }```
• 08-05-2004
hunterdude