| | |
Equation (sum) doesnt add up properly.
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jul 2009
Posts: 25
Reputation:
Solved Threads: 0
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. =)
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. =)
C++ Syntax (Toggle Plain Text)
#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; }
•
•
Join Date: Dec 2007
Posts: 360
Reputation:
Solved Threads: 69
Move this
behind the
C++ Syntax (Toggle Plain Text)
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;
behind the
C++ Syntax (Toggle Plain Text)
cin.ignore(1000, 10);
If you are forced to reinvent the wheel at least try to invent a better one!
Please use code tags - Please mark solved threads as solved
Please use code tags - Please mark solved threads as solved
If you didn't realize this code :
Is useless because numX,numY,numZ is not initialized. You need
to first get num* then calculate it. What you are doing is
calculating junk, then getting num* then showing the junk you
calculated.
Again get user input first into numX,numY,numZ, then calculated
whatever you need to calculate.
-------
num* = numX, numY, numZ
C++ Syntax (Toggle Plain Text)
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;
Is useless because numX,numY,numZ is not initialized. You need
to first get num* then calculate it. What you are doing is
calculating junk, then getting num* then showing the junk you
calculated.
Again get user input first into numX,numY,numZ, then calculated
whatever you need to calculate.
-------
num* = numX, numY, numZ
Last edited by firstPerson; Aug 25th, 2009 at 3:09 pm.
1) What word becomes shorter if you add a letter to it?
[ Solved by : niek_e, Paul Thompson, SgtMe, murtan, xavier666, jonsca]
2) What does this sequence equal to : (.5u - .5a)(.5u-.5b)(.5u-.5c) ...
[*solved by : murtan, xavier666]
3) What is the 123456789th prime numer?![]() |
Similar Threads
- truth table to boolean algebraic equation (Java)
- Add SUM and AVG together also SUM and COUNT together (MS SQL)
- How to Sum a Pascal Triangle (C++)
- Code extract works, but doesnt function properly.. (PHP)
- Help Needed on C++ assignment (C++)
- Keyboard not working properly. (USB Devices and other Peripherals)
- My phpbb forum doesnt work ? (PHP)
- Using a for loop to sum an integer n and call function add_it (C)
Other Threads in the C++ Forum
- Previous Thread: Need daily test and homework
- Next Thread: Need help! with encryption program
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






