|
-
April 6th, 2011, 08:42 AM
#1
Matrices problems with addition and a variable.
Hey everyone, I've got to create a program that calculates matrices in a 2D array, and then add, subtract and display the results. However, i cannot get the addition to work, which i will then use for the subtraction, and i have a problem with "data_input" not being initialized.
here's my code, i hope you can help.
Code:
#include <iostream>
using namespace std;
typedef struct Matrices_varibles{
int numbers [3] [4];
int numbers1 [3];
int numbers2 [4];
int row;
int col;
} Matrices_variables;
void data_input(Matrices_variables datamatrices);
void data_output(Matrices_variables datamatrices);
int askselectioninput();
void add_Matrices(Matrices_variables datamatrices);
void subtract_Matrices(Matrices_variables datamatrices);
void display_Matrices(Matrices_variables datamatrices);
void logout();
void main(){
cout<<"========================================="<<endl;
cout<<"========================================="<<endl;
cout<<"|| Mutltiple Matrices Calculations ||"<<endl;
cout<<"========================================="<<endl;
cout<<"========================================="<<endl;
Matrices_variables Data_input;
int option =0;
data_input(Data_input);
while (true){
option = askselectioninput();
if (option ==1)
{
subtract_Matrices(Data_input);
}
else if (option ==2)
{
add_Matrices(Data_input);
}
else if (option ==3)
{
display_Matrices(Data_input);
}
else if (option ==4)
{
logout();
}
}
}
int askselectioninput(){
int option= 0;
cout<<"==============CHOICES====================="<<endl;
cout<<"||PRESS 1 to SUBTRACT PRESS 2 to ADD||"<<endl;
cout<<"|| PRESS 3 to DISPLAY RESULTS || "<<endl;
cout<<"=============PRESS 4 to QUIT==============="<<endl;
cin>>option;
if (option >0 && option <5){
return option;
}
else {
cout<<"--Incorrect Value--"<<endl<<endl;
return askselectioninput();
}
}
void data_input(Matrices_variables datamatrices)
{
for (datamatrices.row=1; !(datamatrices.row>3); datamatrices.row++)
{ cout<<"Data for row: "<<datamatrices.row<<endl;
for (datamatrices.col=1; !(datamatrices.col>4); datamatrices.col++)
{ cout<<"Type a number: ";
cin>>datamatrices.numbers[datamatrices.row][datamatrices.col];
}
}
}
void data_output(Matrices_variables datamatrices){
cout<<"DISPLAY"<<endl;
for (datamatrices.row=1; !(datamatrices.row>3); datamatrices.row++)
{
for (datamatrices.col=1; !(datamatrices.col>4); datamatrices.col++)
{ cout<<datamatrices.numbers[datamatrices.row][datamatrices.col]<<" ";
}
cout<<"End"<<endl;
}
}
void add_Matrices(Matrices_variables datamatrices){
}
void subtract_Matrices(Matrices_variables datamatrices){
cout<<"SUB"<<endl;
}
void display_Matrices(Matrices_variables datamatrices){
cout<<"DISPLAYING RESULTS :D"<<endl;
for (datamatrices.row=1; !(datamatrices.row>3); datamatrices.row++)
{
for (datamatrices.col=1; !(datamatrices.col>4); datamatrices.col++)
{ cout<<datamatrices.numbers[datamatrices.row][datamatrices.col]<<" ";
}
cout<<"End"<<endl;
}
}
void logout(){
cout<<"Hasta La Vista,"<<endl;
cout<<"--PROGRAM TERMINATED--"<<endl;
exit(0);
}
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
|