Thread: adding statement

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    3

    adding statement

    how can i make another statement when i enter other letters excluding R,P,S printf will be Invalid Letter. I hope someone can help im just beginning in turbo c++


    the code is not mine. The code is working properly i just want to add a new statement.


    Code:
      #include <stdlib.h> 
    #include <ctype.h> 
    /* 
    DEFINE FUNCTION GetInput( Input Text as string ) returns character 
    ..declare result as character value ' ' 
    ..LOOP WHILE ( result is no R S or P ) 
    ....output (text) (Rock, Scissors, Paper) 
    ....input result 
    ..END LOOP 
    ..return result 
    END FUNCTION 
    */ 
    char GetInput(const char *szPlayer) 
    { 
    char cRet = 0; 
    while(!(cRet == 'S' || cRet == 'R' || cRet == 'P')){ 
    printf("%s: (R)ock, (S)cissors, (P)aper > ", szPlayer); 
    fflush(stdin); 
    scanf("%c", &cRet); 
    cRet = toupper(cRet); 
    } 
    return cRet; 
    } 
    int main() 
    { 
    const char *msg[] = { 
    "Paper covers Rock", 
    "Scissor cuts paper", 
    "Rock breaks Scissors", 
    "It's a Draw!" 
    }; 
    
    
    const char *win[] = { 
    ", Player 1 wins!\n", 
    ", Player 2 wins!\n" 
    }; 
    /* ..declare Player1 as character value ' ' 
    ..declare Player2 as character value ' '*/ 
    char cPlayer1 = 0, 
    cPlayer2 = 0; 
    /* 
    MAIN ENTRY POINT 
    ..Player1 = GetInput("Player 1") 
    ..CLEAR SCREEN 
    ..Player2 = GetInput("Player 2") 
    ..CLEAR SCREEN 
    END MAIN 
    */ 
    
    
    cPlayer1 = GetInput("Player 1"); 
    system("cls"); 
    cPlayer2 = GetInput("Player 2"); 
    system("cls"); 
    /* 
    ..IF( ( Player1 is Paper ) AND (Player2 is Rock) ) THEN output Paper covers Rock, Player 1 wins! 
    ..ELSE IF( ( Player1 is Rock) AND (Player2 is Scissors) ) THEN output Rock breaks scissors, Player 1 wins! 
    ..ELSE IF( ( Player1 is Scissors) AND (Player2 is Paper) ) THEN output Scissors cuts paper, Player 1 wins! 
    ..ELSE IF( ( Player2 is Paper ) AND (Player1 is Rock) ) THEN output Paper covers Rock, Player 2 wins! 
    ..ELSE IF( ( Player2 is Rock) AND (Player1 is Scissors) ) THEN output Rock breaks scissors, Player 2 wins! 
    ..ELSE IF( ( Player2 is Scissors) AND (Player1 is Paper) ) THEN output Scissors cuts paper, Player 2 wins! 
    ..ELSE output Its a Draw! 
    
    
    */ 
    if (cPlayer1 == 'P' && cPlayer2 == 'R') printf("%s%s", msg[0], win[0]); 
    else if (cPlayer1 == 'R' && cPlayer2 == 'S') printf("%s%s", msg[2], win[0]); 
    else if (cPlayer1 == 'S' && cPlayer2 == 'P') printf("%s%s", msg[1], win[0]); 
    else if (cPlayer2 == 'P' && cPlayer1 == 'R') printf("%s%s", msg[0], win[1]); 
    else if (cPlayer2 == 'R' && cPlayer1 == 'S') printf("%s%s", msg[2], win[1]); 
    else if (cPlayer2 == 'S' && cPlayer1 == 'P') printf("%s%s", msg[1], win[1]); 
    else printf("%s\n", msg[3]); 
    system("pause"); 
    return 0; 
    }

    Need a help

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    1) This is C, not C++.
    2) Turbo C++ is outdated and not used anymore. Dump it and get a modern compiler and/or IDE (e.g. Visual Studio, Code::Blocks, gcc, clang)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Sep 2015
    Posts
    3
    but can you help with the statement? one of my friend says if i want to learn c++ i must go to the basics haha

  4. #4
    Registered User
    Join Date
    Sep 2015
    Posts
    3
    then i try this code and download turbo c++ (that my friend's recommendation) and it works.

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by anonymous018 View Post
    one of my friend says if i want to learn c++ i must go to the basics haha
    But "basics" does not mean obsolete, nonstandard, irrelevant versions of the language. By not learning modern C++, you do yourself a disservice.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by anonymous018
    but can you help with the statement?
    Possibly, but in the first place you said "the code is not mine". Therefore, you need to understand the code before you start asking for help. Yet, even before you attempt to understand the code, you need to be clear as to what programming language the code is written in.

    Quote Originally Posted by anonymous018
    one of my friend says if i want to learn c++ i must go to the basics haha
    Your friend is right, but C is not the basics of C++. C is a different programming language, though it was used as a base from which C++ was designed.

    Quote Originally Posted by anonymous018
    then i try this code and download turbo c++ (that my friend's recommendation) and it works.
    Your friend has recommended poorly. Refer to the suggestions in Elysia's post #2. It is true that there are C programs that are effectively C++ programs such that they can be compiled with C++ compilers, but in the end if you want to learn C++, you should be learning C++.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by anonymous018 View Post
    but can you help with the statement? one of my friend says if i want to learn c++ i must go to the basics haha
    Your friend is wrong. I suggest you get the book Accelerated C++ and read through that. That will teach get you started with C++.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    The Negativity. LAURENT*'s Avatar
    Join Date
    May 2012
    Posts
    68
    Quote Originally Posted by anonymous018 View Post
    then i try this code and download turbo c++ (that my friend's recommendation) and it works.
    Yeah, you should upgrade. Nobody uses that anymore. I think you should try to learn c++ directly and use this site's tutorial to cover the basics of c++.

    I highly recommend not practicing outdated languages.
    UPDATE! As of 10/6/2014

    https://www.dropbox.com/s/2sj6qwpfbb...t%201.zip?dl=0
    Just find the application file and double click it. Controls are (Arrow keys) (Z) (Z + arrow key) (Spacebar)
    Don't play this crappy update. Wait for the newest one which is far more impressive.

    Official Sonic character poll hosted by some guy at Sega..... Sega of America. Vote for blaze because she OP.
    http://blogs.sega.com/2015/08/28/the...down-heats-up/

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This site's tutorial will not cover the basics and is only good for quick reminders or looking up a specific feature. I would definitely not recommend it to a newbie.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 'If' Statement inside the Switch statement being ignored.
    By howardbc14 in forum C Programming
    Replies: 4
    Last Post: 04-11-2015, 11:45 AM
  2. While statement doesnt work if adding in line within
    By Vespasian in forum C++ Programming
    Replies: 5
    Last Post: 05-28-2013, 07:04 PM
  3. Adding statement between loops
    By SilentPirate007 in forum C Programming
    Replies: 4
    Last Post: 03-01-2010, 04:55 AM
  4. Statement inside a statement.
    By JOZZY& Wakko in forum C Programming
    Replies: 15
    Last Post: 11-05-2009, 03:18 PM
  5. linked list statement 4 adding a node
    By llinocoe in forum C Programming
    Replies: 5
    Last Post: 09-28-2008, 09:52 AM