Blocking While Loop Placement & Program Continuation Problem

Pages: 12
closed account (48T7M4Gy)
debugging is just getting errors etc fixed and therefore getting the expected output.

for the values in the range what do you expect the machine to give you? if it's not what you expect then somethings wrong!

if number is 23 number >= 25 is false, number <= 20 is false, so you wouldn't expect it to print the error message. now, what happens when you run it?
So, 20 to 25 range is for my Tinitial value. Tinitial must be either 20, 21, 22, 23, 24 or 25. if its less than 20 i want an error message to pop up. if its greater than 25 i want an error message to pop up. If the user enters 20,21,22,23,24,or25 then i want the program to continue to the next while loop where i will have them pick between 50 and 100 for my Tside value. 4 of my variables in my long equation have parameters. Once the user picks the right number for the 4 variables. I want my program to put into the equation i wrote to solve and compute it. I have no problem with the equation. Its getting the user to pick the right numbers between the paramters for 4 of my variables , then moving on. Does that make sense ?
Last edited on
i figured it out !! :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;
int main () {

     int number;

     cout << "Enter a number between 20 and 25: ";
     cin >> number;
     while (number < 20 || number > 25)
     {
         cout << "Error ! Enter number again !: ";
         cin >> number;
     }
     return 0;
}
the while loop is when it is false. I was entering <= and >= because that is what i wanted TRUE. Now it makes so much sense ! Thank you for working with me as long as you have. Now when i go to the next while loop i do the same thing ? when i entered 20 my program just stopped. Is that because I hadnt entered anything below it ?
uh oh... this is my last question. I got it to work for 3 of my loops. but on the 0.005 - 0.008 one.. it kept entering my error message non stop. do you know why ? heres my code
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
39
40
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;
int main () {

    int number;
    
    cout << "Enter a number between 20 and 25: ";
    cin >> number;
    while (number < 20 || number > 25)
    {
        cout << "Error ! Enter number again !: ";
        cin >> number;
    }
    
    cout << "Enter a number between 50 and 100: ";
    cin >> number;
    while (number < 50 || number > 100)
    {
        cout << "Error ! Enter number again !: ";
        cin >> number;
    }
    
    cout << "Enter a number between 0.005 and 0.008: ";
    cin >> number;
    while (number < 0.005 || number > 0.008)
    {
        cout << "Error ! Enter number again !: ";
        cin >> number;
    }
    
    cout << "Enter a number between 1 and 50: ";
    cin >> number;
    while (number < 1 || number > 50)
    {
        cout << "Error ! Enter number again: !";
        cin >> number;
    }        return 0;
}
Last edited on
closed account (48T7M4Gy)
don't forget that you have defined number as an integer
oooooooo i see.. ok i made it a double and now it works. Thanks a lot kemort !
closed account (48T7M4Gy)
:)
Topic archived. No new replies allowed.
Pages: 12