Hello Pepeforever,
I think it is time to go back to the beginning and start with answering these questions:
1. Explain what the purpose of the program is and what you want it to do.
2. Explain why have you chosen a do/while loop.
3. Do you know the difference between an if/else, for loop, do/while loop and while loop?
4. What IDE and operating system are you using? Please mention so people will know what you are working with.
Along with what
jonnin posted earlier this should help you understand what you program is doing.
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 41 42
|
#include <iostream>
using namespace std; // <--- Best not to use.
int main()
{
int x{}, y{}; // <--- ALWAYS initialize your variables.
std::cout << "\n Enter 2 numbers (1 2): "; // <--- ALWAYS provide a prompt before input.
cin >> x >> y;
do
{
cout << "\n The smaller value is " << x << '\n';
std::cout <<
"\n The value of 'x' is: " << x <<
"\n The value of 'y' is: " << y << '\n';
} while (x < y);
do
{
cout << "\n The larger value is: " << x << '\n';
std::cout <<
"\n The value of 'x' is: " << x <<
"\n The value of 'y' is: " << y << '\n';
} while (x > y);
do
{
cout << "the smaller value is " << y << '\n';
} while (y > x);
do
{
cout << "the larger value is " << y << '\n';
} while (y > x);
return 0;
}
|
Given the x = 5 and y = 10 you get this:
Enter 2 numbers (1 2): 5 10
The smaller value is 5
The value of 'x' is: 5
The value of 'y' is: 10
The smaller value is 5
The value of 'x' is: 5
The value of 'y' is: 10
The smaller value is 5
The value of 'x' is: 5
The value of 'y' is: 10
The smaller value is 5
The value of 'x' is: 5
The value of 'y' is: 10
|
Given that x = 10 and y = 5 you get this:
Enter 2 numbers (1 2): 10 5
The smaller value is 10 // <--- From the 1st do/while.
The value of 'x' is: 10
The value of 'y' is: 5
The larger value is: 10 // <--- From the 2nd do/while.
The value of 'x' is: 10
The value of 'y' is: 5
The larger value is: 10
The value of 'x' is: 10
The value of 'y' is: 5
The larger value is: 10
The value of 'x' is: 10
The value of 'y' is: 5
|
From the above code put a break point on lines 14 and 23 to watch what your program is doing.
If you are not sure about anything just ask.
It also helps to compile your code before you post it. This way you can include the complete error message(s) that you do not understand.
Andy