fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int a, b, c, d;
  6.  
  7. // รับค่าให้ถูกต้องตามเงื่อนไข
  8. while (true) {
  9. cout << "Enter number 1: ";
  10. cin >> a;
  11. cout << "Enter number 2: ";
  12. cin >> b;
  13. cout << "Enter number 3: ";
  14. cin >> c;
  15. cout << "Enter number 4: ";
  16. cin >> d;
  17.  
  18. if (a >= 1 && a <= 100 &&
  19. b >= 1 && b <= 100 &&
  20. c >= 1 && c <= 100 &&
  21. d >= 1 && d <= 100 &&
  22. a == c && b == d) {
  23. break;
  24. }
  25.  
  26. cout << "Invalid input, please try again.\n\n";
  27. }
  28.  
  29. cout << "\nInput: " << a << ", " << b << ", " << c << ", " << d << endl;
  30.  
  31. // เดินเป็นสี่เหลี่ยม
  32. cout << "Start: Walk straight ";
  33. if (a == 1)
  34. cout << "down ";
  35. else
  36. cout << "up ";
  37. cout << a << " unit and turn left." << endl;
  38.  
  39. cout << "Walk straight for " << b << " units and turn left." << endl;
  40.  
  41. cout << "Walk straight ";
  42. if (c == 1)
  43. cout << "up ";
  44. else
  45. cout << "down ";
  46. cout << c << " unit and turn left." << endl;
  47.  
  48. cout << "End: Walk straight for " << d << " units." << endl;
  49.  
  50. // วาดกรอบ
  51. cout << "+++++++++++++++++++++++++\n";
  52. cout << "Rectangular area = " << b << " * " << a
  53. << " = " << b * a << " unit\n";
  54. cout << "+++++++++++++++++++++++++\n";
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0.03s 25500KB
stdin
Standard input is empty
stdout
#include <iostream>
using namespace std;

int main() {
    int a, b, c, d;

    // รับค่าให้ถูกต้องตามเงื่อนไข
    while (true) {
        cout << "Enter number 1: ";
        cin >> a;
        cout << "Enter number 2: ";
        cin >> b;
        cout << "Enter number 3: ";
        cin >> c;
        cout << "Enter number 4: ";
        cin >> d;

        if (a >= 1 && a <= 100 &&
            b >= 1 && b <= 100 &&
            c >= 1 && c <= 100 &&
            d >= 1 && d <= 100 &&
            a == c && b == d) {
            break;
        }

        cout << "Invalid input, please try again.\n\n";
    }

    cout << "\nInput: " << a << ", " << b << ", " << c << ", " << d << endl;

    // เดินเป็นสี่เหลี่ยม
    cout << "Start: Walk straight ";
    if (a == 1)
        cout << "down ";
    else
        cout << "up ";
    cout << a << " unit and turn left." << endl;

    cout << "Walk straight for " << b << " units and turn left." << endl;

    cout << "Walk straight ";
    if (c == 1)
        cout << "up ";
    else
        cout << "down ";
    cout << c << " unit and turn left." << endl;

    cout << "End: Walk straight for " << d << " units." << endl;

    // วาดกรอบ
    cout << "+++++++++++++++++++++++++\n";
    cout << "Rectangular area = " << b << " * " << a
         << " = " << b * a << " unit\n";
    cout << "+++++++++++++++++++++++++\n";

    return 0;
}