So I am using a while loop and my problem happens when I try and run this code in an online compiler which doesn't have input, it keep looping forever and doesn't wait for input. Is there a way I can force it to wait ?
Please note that it works perfect with Code blocks ide.

#include <iostream>
#include <stdlib.h>

int main()
{
    system("COLOR A");
    bool repeat = true;
    int v1 = 0, v2 = 0;

    std::string sum = "sum", subtract = "subtract", multiply = "multiply", divide = "divide", exponentiation = "exponentiation", squareroot = "squareroot", polynomials = "polynomials", exit = "exit";
    std::string check;

    while(repeat == true)
    {
        std::cout << "Choose what you want to do by typing any of the following: ";
        std::cout << sum << " , " << subtract << " , " << multiply << " , " << divide << " , " << exponentiation << " , " << squareroot << " , " << polynomials << " , " << exit << "." << std::endl;
        std::cin >> check;


        if(check == sum)
        {
            std::cout << "Enter the numbers you want to " << sum << " and press enter." << std::endl;
            std::cin >> v1 >> v2;
            std::cout << "Result is " << v1 + v2 << std::endl;
        }
        if(check == subtract)
        {
            std::cout << "Enter the numbers you want to " << subtract << " and press enter." << std::endl;
            std::cin >> v1 >> v2;
            std::cout << "Result is " << v1 - v2 << std::endl;
        }
        if(check == multiply)
        {
            std::cout << "Enter the numbers you want to " << multiply << " and press enter." << std::endl;
            std::cin >> v1 >> v2;
            std::cout << "Result is " << v1 * v2 << std::endl;
        }
        if(check == divide)
        {
            std::cout << "Enter the numbers you want to " << divide << " and press enter." << std::endl;
            std::cin >> v1 >> v2;
            std::cout << "Result is " << v1 / v2 << std::endl;
        }
        if(check == polynomials)
        {
            std::cout << "Type what kind of polynomial you wil use: " << std::endl;
            std::string linear = "linear", quadratic = "quadratic", cubic = "cubic", quartic = "quartic";
            std::cout << linear << " , " << quadratic << " , " << cubic << " , " << quartic << std::endl;
            std::cin >> check;

                    {
                        if(check == linear)
                        {


                            std::cout << "Type what do you want to preform on the polynomials: " << std::endl;
                            std::string multiply = "multiply", divide = "divide", sum = "sum", subtract = "subtract", exit = "exit";
                            std:: cout << multiply << " , " << divide << " , " << sum << " , " << subtract << " , " << exit << "." <<  std::endl;
                            std::cin >> check;
                            int leadingcoefficient = 0, constantterm = 0;
                            int leadingcoefficienttwo = 0, constanttermtwo = 0;
                            std::string sign;
                            std::string signtwo;
                            if(check == sum)
                            {
                                std::cout << "Type your first linear polynomial numbers starting with the leading coefficient leaving spaces. Example : 4 x +3 And then press enter. " << std::endl;
                                std::cin >> leadingcoefficient >> sign >> constantterm;
                                std::cout << "Type your second linear polynomial numbers starting with the leading coefficient leaving spaces. Example : 3 x -9 And then press enter. " << std::endl;
                                std::cin >> leadingcoefficienttwo >> signtwo >> constanttermtwo;
                                if(sign == signtwo)
                                {
                                    if(constantterm + constanttermtwo > 0)
                                    {

                                        std::cout << "Result is " << leadingcoefficient + leadingcoefficienttwo << " " << sign << " + " << constantterm + constanttermtwo << std::endl;
                                    }
                                    if(constantterm + constanttermtwo < 0)
                                    {
                                        std::cout << "Result is " << leadingcoefficient + leadingcoefficienttwo << " " << sign << "  " << constantterm + constanttermtwo << std::endl;
                                    }
                                    if(constantterm + constanttermtwo == 0)
                                    {
                                        std::cout << "Result is " << leadingcoefficient + leadingcoefficienttwo << " " << sign << std::endl;
                                    }
                                }
                                else
                                {
                                    std::cout << "Your linear polynomials can't be added as " << sign << " of first linear isn't equal to " << signtwo << " of the second linear" << std::endl;
                                }
                            }
                            if(check == subtract)
                            {
                                std::cout << "Type your first linear polynomial numbers starting with the leading coefficient leaving spaces. Example : 4 x +3 And then press enter. " << std::endl;
                                std::cin >> leadingcoefficient >> sign >> constantterm;
                                std::cout << "Type your second linear polynomial numbers starting with the leading coefficient leaving spaces. Example : 3 x -9 And then press enter. " << std::endl;
                                std::cin >> leadingcoefficienttwo >> signtwo >> constanttermtwo;
                                if(sign == signtwo)
                                {
                                    if(constantterm - constanttermtwo == 0)
                                    {
                                        std::cout << "Result is " << leadingcoefficient - leadingcoefficienttwo << " " << sign << std::endl;
                                    }
                                    if(constantterm - constanttermtwo > 0)
                                    {
                                        std::cout << "Result is " << leadingcoefficient - leadingcoefficienttwo << " " << sign << " + " << constantterm - constanttermtwo << std::endl;
                                    }
                                    if(constantterm - constanttermtwo < 0)
                                    {
                                        std::cout << "Result is " << leadingcoefficient - leadingcoefficienttwo << " " << sign << "  " << constantterm - constanttermtwo << std::endl;
                                    }
                                }
                                else
                                {
                                     std::cout << "Your linear polynomials can't be subtracted as " << sign << " of first linear isn't equal to " << signtwo << " of the second linear" << std::endl;
                                }
                            }
                        }
                    }



        }
        if(check == squareroot)
        {
            std::cout << "Enter the number you want sqaured and press enter. " << std::endl;
            float input = 0, multiplier = 0;
            std::cin >> input;
            if(input >= 0)
            {
                multiplier = input;
                while(multiplier != (input * input))
                {
                    input--;
                }
                std::cout << "Result is " << input << std::endl;
            }
            else
            {
                std::cout << "You can't get a squareroot for a negative number! Math Error. " << std::endl;
            }

        }
        if(check == exponentiation)
        {
            std::cout << "Enter the numbers by which the first is the base and second is the index." << std::endl;
            std::cin >> v1 >> v2;
            float holder = v1;
            int i = v2;
            if(i > 0)
            {

                while(i > 1)
                {
                    i--;
                    holder *= v1;
                }
            }
            if(i < 0)
            {
                holder = 1/holder;
                while(i < -1)
                {
                    i++;
                    holder /= v1;
                }
            }
            if(i == 0)
            {
                holder = 0;
            }
            std::cout << "Result is " << holder << std::endl;
        }


        if(check == exit)
        {
            repeat = false;
        }
    }
        return 0;
    }

Recommended Answers

All 2 Replies

This forums provides help to users who have specific questions. It isn't a free programming advice column.

Alright fixed :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.