Hello i am a bit new in C++. i started to take C++ 4 days ago hehe and honestly i love it.
now im trying to do is a 3x3 determinant and it is giving me a small problem i tried to find this.

``````1 2 3
4 5 6
7 8 9
``````

the answer is suppose to be 0 but on the C++ i made i get 42

then played around with the order and now i get 72. i don't know what it is but here is what i have so far.

``````// 3x3 Determinants.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

void main()
{
int a1,a2,a3,b1,b2,b3,c1,c2,c3,d; //a=column1,b=rcolumn2,c=column3,d=determinants
cout<<"a1   ";
cin>>a1;
cout<<"b1   ";
cin>>b1;
cout<<"c1   ";
cin>>c1;
cout<<"a2   ";
cin>>a2;
cout<<"b2   ";
cin>>b2;
cout<<"c2   ";
cin>>c2;
cout<<"a3   ";
cin>>a3;
cout<<"b3   ";
cin>>b3;
cout<<"c3   ";
cin>>c3;
d=((a1*b2*c3)+(a3*b3*c1)+(a3*b1*c2)) + (-c1*-b2*-a3)+(-c2*-b3*-a1)+(-c3*-b1*-a2);

cout<<"Determinant =   "<<d
<<endl;
}
``````

(Watch what you do with those minus signs.)

Good luck!

hahahahah omg wow im such an idiot after spending a bit more time with it i tried something else and move some things around thanks for the post it helped i actually saw what i did wrong now this is what my new program looks like and it works great.

``````#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

void main()
{
int a1,a2,a3,b1,b2,b3,c1,c2,c3,d,d2,dt; //a=column1,b=rcolumn2,c=column3,d=determinants,determinant 2,determinant total
cout<<"a1   ";
cin>>a1;
cout<<"b1   ";
cin>>b1;
cout<<"c1   ";
cin>>c1;
cout<<"a2   ";
cin>>a2;
cout<<"b2   ";
cin>>b2;
cout<<"c2   ";
cin>>c2;
cout<<"a3   ";
cin>>a3;
cout<<"b3   ";
cin>>b3;
cout<<"c3   ";
cin>>c3;
d=((a1*b2*c3)+(b1*c2*a3)+(c1*a2*b3));
d2=((a3*b2*c1)+(b3*c2*a1)+(c3*a2*b1));
dt=d-d2;
cout<<"Determinant =   "<<dt
<<endl;
}
``````

i know there is a lot more tricky stuff but this is a huge step for me lol. i still need to set it so when you input neg numbers and everything else.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.