Can anyone help with a while loop?

I missed class on the days we did it and am completely lost on it. We need to modify a previous code we did and add a while loop to it. The original code is here, we need to add a while loop to be able to execute it at least 6 times. Also this code works it just needs a while loop added which I have no idea what it is. Thanks in advance.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// This is a program that when given the x and y coordinates of two points on a line,
// the program calculates and displays the slope and the midpoint of that line.
#include <iostream> 
using namespace std;
int main()
{
 double x1=0;
 double x2=0;
 double y1=0;
 double y2=0;
 double slope=0;
 double midpoint=0;
 //prompt
 cout << "Please enter the x coordinate of the first point on a line:" ;
 cin >> x1;
 cout << "Please enter the y coordinate of the first point on a line:" ;
 cin >> y1;
 cout << "Please enter the x coordinate of the second point on the line:" ;
 cin >> x2;
 cout << " Please enter the y coordinate of the second point on the line:" ;
 cin >> y2;
 
 slope=(y2-y1)/(x2-x1);
 midpoint=((x1+x2)/2);
 midpoint=((y1+y2)/2);
 cout << "The first point's coordinate is:" "("<< x1 <<","<< y1 <<")"<<endl;
 cout << "The second point's coordinate is:" "("<< x2 <<","<< y2 <<")"<<endl;
 cout << "The slope of the line is: ("<< slope <<")"<<endl;
 cout << "The midpoint is: ("<< midpoint <<")"<<endl;
 system("pause");
 return 0;
http://programming.msjc.edu/cpp/4Repetitionnbsp;nbsp;nbsp;.aspx#LiveTabsContent2875151-lt

Follow that section, that should help you understand how to do for, while, and do while loops.
Topic archived. No new replies allowed.