Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9061153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:24:49+00:00 2026-06-16T15:24:49+00:00

I want to write a program to solve a simple guessing game. I’m learning

  • 0

I want to write a program to solve a simple guessing game. I’m learning about command line piping and redirects, and so I was wondering if this is even possible.

Basically I want the output of one to be the input of the other, and then the output of that to be the input of the other.

This is all just for fun so I can learn, I know I can change the source code of the guessing game and include the solving algorithm, but just for fun let’s assume I don’t have the source code.

Is this even possible? Here’s my code:

//GuessingGame.cc    

#include <cstdlib>
#include <iostream>

using namespace std;

int main() {
    srand(time(NULL));
    int number = rand()%100; 
    int guess = -1;
    int trycount = 0;

    while(guess != number && trycount < 8) {

        cout << "Please enter a guess: ";
        cin >> guess;

        if(guess < number)
            cout << "Too low" << endl;

        else if(guess > number)
            cout << "Too high" << endl;

        trycount++;
    }

    if(guess == number)
        cout << "You guessed the number!";

    else 
        cout << "Sorry, the number was: " << number;

    return 0;
}

Solver.cc

#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char* argv[]) {

    string prompt;
    int high = 100;
    int low = 0;
    int guess = 50;

    getline(cin,prompt);
    if(prompt == "Please enter a guess: ")
        cout << guess;

    while(true) {
        getline(cin,prompt);
        if(prompt == "Too low")
            low = guess;

        else if(prompt == "Too high")
            high = guess;

        else if(prompt == "You guessed the number!")
            return 0;

        guess = (low+high)/2;
        cout << guess;
    }
}

I hope you understand what I’m doing, and I don’t care so much about the program, it’s just an example. The main question is if you can interact with two different programs, using redirects and piping and such. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:24:50+00:00Added an answer on June 16, 2026 at 3:24 pm

    A pipe is by definition a one-way communication device. However it can be solved by using two pipes, one in each direction. The problem is that it can’t be done easily through a shell, you have to make a program to set up the pipes, creates the processes for your programs and then executes them with the pipes set up as the correct input/output channels.

    The only way I can think about how to make this possible through a shell, is to use the mkfifo command to create two pipes. Start one program in the background with the input and output redirected from/to the correct pipes, and then do the same with the other program but use the other pipe as input and output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a program in Prolog that confirms if a b-tree of
I want to write a program to contact a PHP script online, and show
I want to write a program which replaces each specific letter by text according
I want to write a program that automatically downloads all the csv files on
I want to write a program (preferably in java) that will parse and analyze
I want to write a program that would take a string, let's say Fox
I want to write a program to find the n-th smallest element without using
I want to write a program to link with binaries already created with VC++.
I want to write a program from scratch to see the sockets activity, what
I want to write a program that analyzes your fantasy baseball team and notifies

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.