In case 2 I try to print the variables, but it shows me wrong values I tried to do it in a function and the same thing happened, with pointers and neither did the program in the enter function does everything right try to print from it and It showed what was due. The problem is showing everything in another function.
#include <iostream>
#include <math.h>
#include <windows.h>
using namespace std;
struct datos{
int n;
float m, b, sx, sy, sx2, sxy, X[20], Y[20];
};
typedef datos v;
void inicio();
void menu();
void ingresar_operaciones(struct datos d);
v mostrar(struct datos d);
int i;
int main() {
int op;
v D;
inicio();
do {
menu();
cin >> op;
switch(op) {
case 1:
ingresar_operaciones(D);
break;
case 2:
for(i = 0;i<D.n;i++) {
cout << D.X[i] << endl;
cout << D.Y[i] << endl;
}
cout << D.sx << endl;
cout << D.sy << endl;
cout << D.sx2 << endl;
cout << D.sxy << endl;
cout << D.m << endl;
cout << D.b << endl;
break;
case 3:
cout << "saliendo del programa" << endl;
system("pause");
return 0;
default:
cout << "opcion invalida" << endl;
break;
}
} while(op! = 3);
}
void menu () {
cout << "#1 ingresar" << endl;
cout << "#2 mostrar" << endl;
cout << "#3 salir" << endl;
}
void ingresar_operaciones(struct datos d) {
float ms2, ms1, mi1, mi2, mbi, bs1, bs2;
d.sx = 0, d.sx2 = 0, d.sxy = 0, d.sy = 0;
bool c = false;
cout << "ingrese cantidad de datos" << endl;
cin >> d.n;
do {
for(i = 0;i<d.n;i++) {
cout << "ingrese el valor #" << i+1 << " de las X(variables independientes)" << endl;
cin >> d.X[i];
cout << "ingrese el valor #" << i+1 << " de las Y(variables dependientes)" << endl;
cin >> d.Y[i];
d.sx = (d.sx+d.X[i]);
d.sy = (d.sy+d.Y[i]);
d.sx2 = (d.sx2+(pow(d.X[i], 2)));
d.sxy = (d.sxy+(d.X[i]*d.Y[i]));
}
cout << "estan correctos los datos? S(1)/N(0)" << endl;
cin >> c;
} while(c = = false);
ms2 = (d.n*d.sxy);
mi1 = (pow(d.sx, 2));
mi2 = (d.n*d.sx2);
mbi = (mi1-mi2);
ms1 = (d.sx*d.sy);
d.m = ((ms1-ms2)/mbi);
bs1 = (d.sxy*d.sx);
bs2 = (d.sy*d.sx2);
d.b = ((bs1-bs2)/mbi);
cout << d.m << endl;
cout << d.b << endl;
cout << "Y(x) = " << d.m << "x+" << d.b << endl;
system("pause");
}
v mostrar(datos d) {
}
void inicio() {
cout << "bienvenido" << endl;
}