|
-
April 28th, 2011, 01:20 PM
#1
Adding Two-Dimensional arrays together
Hey everyone, I'm having a little problem with adding two arrays together, as part of a Matrices program. Ive got the code for adding the matrices, I really dont think its right at all.
Here's the code
Code:
#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;
int askselectioninput();
int main()
{
cout<<"============================="<<endl;
cout<<"|| Calculation of Matrices ||"<<endl;
cout<<"============================="<<endl;
int numbers[3][4];
int row, col;
int option = 0;
int result =0;
for (row=1; !(row>3); row++)/
{ cout<<"Data for row: "<<row<<endl;
for (col=1; !(col>4); col++)
{ cout<<"Type a number: ";
cin>>numbers[row][col];
}
cout<<"Matrices Inserted.."<<endl;
}
while (true){
option = askselectioninput();
if (option ==1)
{
cout<<"==================================="<<endl;
cout<<"||Addition of Current Matrices Data||"<<endl;
cout<<"==================================="<<endl;
for (row=1; !(row>3); row++)
{
for (col=1; !(col>4); col++)
cout<<row + col<<" ";
}
cout<<"Results Successfully Displayed, returning to Main-Menu"<<endl<<endl<<endl;
}
else if (option ==2)
{
cout<<"======================================"<<endl;
cout<<"||Subtraction of Current Matrices Data||"<<endl;
cout<<"======================================"<<endl;
for (row=1; !(row>3); row++)
{
for (col=1; !(col>4); col++)
cout<<row - col<<" "<<endl;
}
}
else if (option ==3)
{
cout<<"==================================="<<endl;
cout<<"||Displaying Current Matrices Data||"<<endl;
cout<<"==================================="<<endl;
cout<<"The current results are: "<<endl;
for (row=1; !(row>3); row++)
{
for (col=1; !(col>4); col++)
{ cout<<numbers[row][col]<<" ";
}
cout<<" "<<endl;
}
cout<<"Results Successfully Displayed, returning to Main-Menu"<<endl<<endl<<endl;
}
else if (option ==4)
{
cout<<"==================================="<<endl;
cout<<"||Multiplying Current Matrices Data||"<<endl;
cout<<"==================================="<<endl;
}
else if (option ==5){
cout<<"--Program...TERMINATED--"<<endl;
cout<<"--I'll BE BACK--"<<endl;
exit (1);
}
}
}
int askselectioninput(){
int option= 0;
cout<<"==============YOUR TRANSACTION CHOICES==================="<<endl;
cout<<"Press 1 for Addition Press 2 for Subtraction"<<endl;
cout<<"press 3 for Display Balance Press 4 for Mutliplication"<<endl;
cout<<"===============Press 5 for Quit=========================="<<endl;
cin>>option;
if (option >0 && option <6){
return option;
}
else {
cout<<"--Incorrect Value--"<<endl<<endl;
return askselectioninput();
}
}
P.S The rows and cols are meant to be 1 in this code
Code:
for (row=1; !(row>3); row++)
{
for (col=1; !(col>4); col++)
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|