Thread: Why i should command twice to execute this simple C program in Ubuntu Terminal?

  1. #1
    Registered User
    Join Date
    Jul 2018
    Posts
    2

    Why i should command twice to execute this simple C program in Ubuntu Terminal?

    Could you please let me know why i should command twice for running this C code in Ubuntu terminal gcc compiler. one for entering data another for (if) part
    Code:
    
    #include<stdio.h>
    int main(){
        char p;
        printf(" Please enter the grade : ");
        scanf(" %c ", &p);
        if (p=='A') {
            printf("\n your score is excellent");
            }
        else if (p=='B'){
            printf("\n your score is good");
                }
        else if (p=='C'){
            printf("\n your score is fiar");
                }
        else if (p=='D'){
            printf("\n your score is poor");
                }
        else {
            printf("\n you should enetr 'A' or 'B' or 'C' or 'D' ");
            }
    }
    
    

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,669
    Try putting the \n at the end of each printf, which is the usual way to do things.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jul 2018
    Posts
    2
    Thank you Dear. Salem.

  4. #4
    Registered User
    Join Date
    Oct 2017
    Posts
    36
    Also try to leave meaningful comments in your code. This goes a long way in helping those that will read your code understand your thought trend or program flow.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Command for making a program execute faster
    By Nyah Check in forum Linux Programming
    Replies: 2
    Last Post: 04-14-2014, 06:08 AM
  2. Execute a command from C code in a different terminal
    By poornaMoksha in forum C Programming
    Replies: 5
    Last Post: 12-13-2011, 08:04 AM
  3. execute the run command from c program ...?
    By sma88 in forum C Programming
    Replies: 2
    Last Post: 02-22-2010, 09:35 AM
  4. Replies: 8
    Last Post: 09-16-2006, 01:18 PM
  5. Simple program that wont execute
    By Extropian in forum C Programming
    Replies: 17
    Last Post: 07-23-2005, 11:50 AM

Tags for this Thread