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

  • SEARCH
  • Home
  • 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 6931397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:34:19+00:00 2026-05-27T11:34:19+00:00

Hello is there a different way to convert a int back to a char

  • 0

Hello is there a different way to convert a int back to a char see comment about half way down the code. Im thinking the use of a switch or an if statement but i cannot figure out hot to apply it. i used char RPS[] = {‘?’, ‘R’, ‘P’, ‘S’};

  #include <iostream>
    using namespace std; 
    #include <ctime>
    #include <cstdlib>

    //human choice function
    int hchoice()
    {
        char entry;
        int usrchoice = 0;

        while (1)    
         {
         cout <<"Choose R for Rock P for Paper, S for Sissors or Q for quit ";
         cin >> entry;
         cin.ignore(1000, 10);
         switch (toupper(entry)){
         case 'R':
           usrchoice = 1;
           break;
         case 'P':
           usrchoice = 2;
           break; 
         case 'S': 
           usrchoice = 3;
           break; 
         case 'Q':
           usrchoice = -1; 
           break; 
         } 
         if (usrchoice != 0)break;

         cout << "Invalid Entry" <<endl;


        }
    return usrchoice;
    }
    //Computer choice function
    int compchoice()
    {
          return (1 + rand() % 3);
    }
    void printresults(int computer, int human)
    {
    //Number to char converter? Can i use a switch here?
    char RPS[] = {'?', 'R', 'P', 'S'};

     cout << "Computer:" << RPS[computer];
     cout << ", Human:" << RPS[human];
     cout << ",  ";

    if (computer == human){
      cout <<"tie";
    }
    else if ( ( human==1 && computer == 2) || (human == 2 && computer == 3) || (human == 3 && computer == 1)){
    cout << "computer wins!";
    }
    else {
    cout <<"Human Wins!";
    }
    cout << endl;


    }


    int main()
    {
     // initialize the computer's random number generator
    srand(time(0)); rand();
      // declare variables
     int human = 0, computer = 0;

      // start loop
    while (1)  
    {
        // determine computer's choice
        computer = compchoice();
        // prompt for, and read, the human's choice
        human = hchoice();
        // if human wants to quit, break out of loop
           if (human == -1) break;
        // print results
         printresults(computer, human);
        cout << endl;
      // end loop
    }//while
      // end program
     return 0;
    }
  • 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-05-27T11:34:20+00:00Added an answer on May 27, 2026 at 11:34 am

    You could use a switch there, or a series of if statements. However, what you have right now is by far the most concise and — I would argue — the easiest to read.

    One more general thing that I would suggest is to use symbolic constants (e.g. an enum) instead of the hard-coded numbers 1, 2 and 3 that you have in several places in your code.

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

Sidebar

Related Questions

Hello I am looking to see if there are any modules for drupal 6
is there a way to display different TextFormat/Style per item in ListBox Example: Data1:
In java is there any elegant way to compare two different StringBuilders and copy
Hello there and Merry Christmas !!! I am new to WPF and I am
Hello there Stack Overflow, I hope you'll help me with my very first question
I want to include Core Location and I'm trying to follow this tutorial: http://www.mobileorchard.com/hello-there-a-corelocation-tutorial/
Hello is there a class that does a pretty conversion?
Possible Duplicate: New Cool Features of C# 4.0 Hello, There are several(many) questions at
I was reading the Gallery View tutorial : http://developer.android.com/resources/tutorials/views/hello-gallery.html . Is there anyway I
Is there a way for GCC to produce a warning while linking libraries that

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.