Quiz #3 Part#1

I had some help from Here, and from the blogpost of some of my classmates, but anyways, this first part was kind of a problem for me because of this…

Screenshot11.1.png which actually continues going down, but anyways I couldn’t understand what was wrong with this, until I discovered that I had declared a variable like 3 times. Now this is how the program should look.

Screenshot11.2.png

Once you get to understand what the program does, it’s not so easy to write it, but the best way to do it is by writting a function for the process, before starting the main program.

Here is the function I used, but the full coding is HERE

float distance (float x1, float  x2, float  y1, float  y2) {
float dis;
dis=sqrt((x2-x1)*(x2-x1)+((y2-y1)*(y2-y1)));
return dis;
}

After declaring the variable (dis) = distance we can ask the user for values for (x1,x2,y1,y2) and writing the formula, in order to get the value “dis=distance(x1,x2,y1,y2);”

Screenshot11.3.png

First I thought of using “int”, but after looking at someone elses job, I decided to use “float”, even though I think you can also use “double”. I also saw that you can ask for two variables at once by writting (cout<<“…”<<endl; cin>>x>>y).

 

 

 

CC BY-SA 4.0 Quiz #3 Part#1 by canadamike17 is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.