hello everyone...
i wrote a basic program for my C++ class that includes SUMs and while loops.
its fairly self explanatory, but i am not getting the correct SUMs for my outputs.
apparently, i am missing something extremely important somewhere here.
can someone take a look and give me a few hints as to why my outputs are coming out the way they are...
thank you.
note: why i have so much variables here is because my teacher wants it that way. i would use an array to make the program look neater, but i was instructed to keep it as simple and as basic as possible. =)
#include <iostream>
using namespace std;
int main()
{
int numX;
int numY;
int numZ;
int sum1 = numX - numZ;
int sum2 = numX - numY + numZ;
int sum3 = numX + numY;
int sum4 = numX + numY + numZ;
int sum5 = numX;
int sum6 = numX - numY - numZ;
int sum7 = numX - numY;
int sum8 = numX + numY - numZ;
int sum9 = numX + numZ;
int totalA = sum1 + sum2 + sum3;
int totalB = sum4 + sum5 + sum6;
int totalC = sum7 + sum8 + sum9;
int totalD = sum1 + sum4 + sum7;
int totalE = sum2 + sum5 + sum8;
int totalF = sum3 + sum6 + sum9;
while (cin)
{
cout << "Please enter 3 integers separated by spaces: (enter non-digit to quit)" << endl;
cin >> numX >> numY >> numZ;
cin.ignore(1000, 10);
cout << "The magic square is:" << endl;
cout << sum1 << sum2 << sum3 << " = " << totalA << endl;
cout << sum4 << sum5 << sum6 << " = " << totalB << endl;
cout << sum7 << sum8 << sum9 << " = " << totalC << endl;
cout << "---------------" << endl;
cout << totalD << totalE << totalF << endl;
cout << " " << endl;
cout << " " << endl;
}
cin.get();
return 0;
}