Different Compiler Error

Hello everyone I'm new to C++, and need help a with a program.

#include<iostream> // std::cout, std::endl
#include <iomanip> // std::setfill, std::setw
using namespace std;

int main(){
int x=0,y=0,temp=0; //Always declare variables at the "top", if possible pre-assign or initialize them with a value.

cout <<"A 4x4 multiplication table\n";
cout <<"Provide X value (between 1 to 5)\n";
cin >>x;
temp=x;
cout <<"Provide Y value (between 1 to 5)\n";
cin >>y;

cout<< "\t"<<"Y\n";
x=temp;
cout<< "\t"<<y--<<"\t"<<x--*y<<"\t"<<x--*y<<"\t"<<x--*y<<"\t"<<x--*y<<"\n";
x=temp;
cout<< "\t"<<y--<<"\t"<<x--*y<<"\t"<<x--*y<<"\t"<<x--*y<<"\t"<<x--*y<<"\n";
x=temp;
cout<< "\t"<<y--<<"\t"<<x--*y<<"\t"<<x--*y<<"\t"<<x--*y<<"\t"<<x--*y<<"\n";
x=temp;
cout<< "\t"<<y--<<"\t"<<x--*y<<"\t"<<x--*y<<"\t"<<x--*y<<"\t"<<x--*y<<"\n";
x=temp;
cout<< "\t\t"<<x--<<"\t"<<x--<<"\t"<<x--<<"\t"<<x--<<"\t"<<"X";
return 0;
}

^^^^^ That is the program, I type 5 for X and 5 for Y as well. My output ends up showing 5 10 15 20 25 on the top first line, but my friend's top first line shows different numbers. Could you help me edit this program so that me and my friend both get the same output, or in other words to get the same answers in any C++ compiler? Thanks for the help in advance!
> but my friend's top first line shows different numbers

What? I dont understand what you're asking for, the program works fine.

Edit: what kind of compiler error does your friend get? What compiler or IDE does he use? What do you use?
Last edited on
Yes it works, but the answers when I type 5 & 5 aren't the same when he types 5 &5. We are running different windows versions, but have the same Dev C++ compiler.
Thanks for the quick reply by the way TarikNeaj
Whats the difference between your output and his output?
In his output, all the calculations were done wrong, so after the compiler does the same multiplication (like in mine) he gets different numbers.

I believe it has something to do with operand evaluation order, however i'm not too sure.
Maybe try putting some brackets around your calculations. Like here x--*y

However I hade no idea why this is happening, hopefully someone more informed can explain.
do you mean these [ ] ?
I dont see any brackets in your reply
Last edited on
Your code has undefined behaviour.

You have a chain of operators in same statement.
cout << A << B << C;
It is deterministic that the value of A is printed first, then the value of B and last the value of C. However, the code has to compute the values of A, B and C before they are passed to the << operator. Those three computations are not ordered and can be evaluated in whatever order.
How would I fix that?
Use for-loops.
Shoot I haven't learned that, any chance you could edit my program to include it, and afterwards paste here? If you don't have the time to do so I totally understand.
We're you able to figure this one out?
I ended up kind of rewriting the program.
Topic archived. No new replies allowed.