C++ So I got this problem http://screencast.com/t/bmZlQ2vCjD And this is the answer: http://screencast.com/t/MpX2LqIIB I dont understand why if (x1 == x2) then cout << "y=" << x1; That doesn't make any sense mathematically or am I missing something here?
Crap. It HAD to be C++. Well, I can try :p
the only thing I can think of is that it's like that in the 3rd set of plots in the second table.
if `x1 == x2` then it means the slope is `0`
If x1 = x2, then since the x-cordinates are equal, its distance from y axis is constant, means its the vertical line. and equation of vertical line is of the form y=c where c = x-coordinate = x1 here
When the slope is `0` you don't want to show the `mx` part.
infinite slope actually.
@ hartnn why nessesarily x1 and not x2 or x ?
you may use x2 also, both x1 and x2 are equal. so, cout << "y=" << x2; also works.
Then the code is a bugged, it should be `x = ` not `y = `
and why not y1 - y2 = x too and every other combination with y
oh, yes, it must be cout << "x=" << x1; and not y=
equation of vertical line is x=x
*x=c
So the solution is wrong?
wio, actually, it shouldn't be x=x1. look at the third set of plots in the second table, and what is says the outcome should be.
that table is incorrect, x1=x2=-1 implies x=-1
Solution: Kill your teacher.
:D
thats the only flaw, should be cout << "x=" << x1;
so if x1=x2 then the equation of the line is x=x1 ??
@hartnn
Yes....
yes, x=x1 which is same as x=x2
if y1=y2, means its horizontal line, so it must be y=c where c here is y1 or y2 so, yes, thats incorrect.
so we have 2 flaws so far , might even be 3 or 4 -_- I need to dig out the errors that my teacher did -_-
that way, you learn better.
Maybe if we take into consideration the whole if statement, it makes sense? Like: http://screencast.com/t/syqMgbO9QJ I can't say that I have mastered C++ either
nah, its just incorrect. if there are no brackets { and } then only one line condition is assumed, like here. else , to make a block of instructions as condition, we need curly brackets {...}
thats correct, if m=1, then from y=mx+c you'll have the equation of the form y=x \(\pm\)c so the part y=x was displayed first.
`I see, and one last thing, what about this? http://screencast.com/t/McijZitgnKD Isn't it stupid to show y = x --c ?
thats not shown - is displayed first. then, -c is calculated. , so the second - is for making the 'c' negative and first one is for 'displaying' negative sign.
like if c came out to be -2, then -c = 2 and displayed will be y=mx-2
I mean like, if 3 is calculated with -c it will be -3 right? so we have cout << "-" << -3; "-" will be - in the message, so the overall outcome --3?
what 'c' value you have taken ?
if c=3, means c is positive, so it will execute the last else statement, cout <<"+"<<c and display +3 if c=-3, then it will execute middle else statement cout<<"-"<<-c {Note : -c=3}\ and displayed will be -3
got it now ?
I see! Thank you!!
welcome ^_^
Join our real-time social learning platform and learn together with your friends!