0

My code is: Is it possible to put this in a window instead of opening up a command prompt as I feel that would be more user-friendly? And would just look better overall I have Searched online and haven’t found any way to put any code in a window.

#include <iostream>

using namespace std;

int main()
{
    while (true) {
        string s;
        int n, i, m = 0, flag = 0;
        cout << "(press 'x' to exit) Enter the Number to check if It's a prime Number or not: ";
        cin >> s;

        if (s == "x")
            break;

        n = atoi(s.c_str());
        m = n / 2;

        for (i = 2; i <= m; i++)
        {
            if (n % i == 0)
            {
                cout << "That's not a prime number." << endl;
                flag = 1;
                break;
            }
        }
        if (flag == 0)
            cout << "That's a prime number." << endl;

    }
}
Ghasem Ramezani
  • 2,683
  • 1
  • 13
  • 32
SlothGamer
  • 84
  • 10
  • There are plenty of tutorials on how to do GUI programming on Windows, both using the low-level Windows API and libraries and frameworks which help you abstract the often tedious bits needed for GUI applications. – Some programmer dude Sep 09 '21 at 07:19
  • Also, in a GUI you can't really use `std::cin` and `std::cout`, you have to put text into *controls* and display them inside the GUI itself. You also can't have a `while (true)` loop as that will stop the GUI from responding, you have to learn *event handling*. A good tutorial should have all the information you need. – Some programmer dude Sep 09 '21 at 07:20
  • A console is also just a window that displays some text. What do you expect or want to change? I guess you are using some tiny integrated console or the old windows command prompt? Take a look at the new stuff like powershell core and windows terminal. Overall it's not really clear what you are trying to achieve. – Lukas-T Sep 09 '21 at 07:37

1 Answers1

0

You can follow the microsoft docs tutorial for creating a window.

You won't be able to use std::cout and std::cin as these are console specific.

  • Are there any substitutions for std::cout and std::cin as these are major bits of my code. – SlothGamer Sep 09 '21 at 07:21
  • I would strongly recommend you to read the docs, the short answer is their won't be a quick substitution method. – Garfield1002 Sep 09 '21 at 07:25
  • 1
    @SlothGamer So you want to do is have a window and have std::cout draw text on the window and std::cin to read from the window's keypress queue, just like the console window does? Maybe this helps: https://stackoverflow.com/questions/191842/how-do-i-get-console-output-in-c-with-a-windows-program – Jerry Jeremiah Sep 09 '21 at 08:38