Beginner with looping

I am stuck my loop need to be repeated untill the value of height is more than 1.8 or the value of weight is less than 100.

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
33
34
35
36
37
38
  #include <iostream>

using namespace std;

int main()
{

    //declaring variables
    int weight;
    float height;

    cout << "Please key in the height followed by the weight: ";
    cin >> height;
    cout << "Please key in the weight: ";
    cin >> weight;

    // repeat untill height > 1.8
    while (height < 1.8)
    {
            cout << "The height can not be less than 1.8: ";
            cout << "Re-enter the height value: ";
            cin >> height;
    }

    // repeat untill weight < 100
    while (weight < 100)
    {
            cout << "The weight can not be more than 100: ";
            cout << "Re-enter the weight value: ";
            cin >> weight;
    }

    return 0;
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

using namespace std;

int main()
{
	float height;
	do
	{
		cout<<"Enter your height: " <<endl;
		cin>>height;
		if ( height < 1.8 )
		{
			cout<<"Height may not be under 1.8"<<endl;
			cout<<"Please enter your height again: " <<endl;
			cin>>height;
		}
		else
		{
			cout<<"Thank you for entering your height."<<endl;
		}
	}while ( height < 1.8 );
	return 0;
}
Thanks look good
Glad i could help :)
Topic archived. No new replies allowed.