Page 3 of 9 FirstFirst 123456 ... LastLast
Results 21 to 30 of 82
  1. #21

    @xiao

    ambot asa ni gikan ani, ang gi input niya kay with spaces pero ang iyang gi pa output kay with comma, instead gi ingon samples sa TS kay with comma ang input, mas maayo if buhat nalang siya ug full program.

    Quote Originally Posted by MarkCuering View Post
    PHP Code:
    #include <stdio.h>

    int main(int argcchar *argv[])
    {

        
    int ab;

         
    printf("Enter two integers separated by a space: ");
         
    scanf("%d %d", &a,&b);
        
    printf("%d, %d\n"a,b);

        return 
    0;


    OUTPUT:

  2. #22
    Quote Originally Posted by marcdaven View Post

    Code:
    int add(int, int);
    int subtract(int, int);
    float divide(int, int);
    int multiply(int, int);
    sayop imong function prototypes above, it should match the function declarations nimo so the correct one should be

    Code:
    int add(int a, int b);
    int subtract(int a, int b);
    float divide(int a, int b);
    int multiply(int a, int b);
    Another thing

    Quote Originally Posted by marcdaven View Post

    Code:
    scanf("%c", &c);
    do not use scanf when dealing with characters and strings kay naa jud cya tendency mo skip sa input nga part, resulta wala madawat nga value ang nag hulat sa output gkan sa scanf(). Use the code below instead
    Code:
    c=getche();
    HERE's THE COMPLETE WORKING CODE

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    int add(int a, int b);
    int subtract(int a, int b);
    float divide(int a, int b);
    int multiply(int a, int b);
    
    void main(void)
    {
     int a, b, d, e, f;
     float g;
     char c;
     clrscr();
     
     printf("Enter two integers separated by a space:\n");
     scanf("%d %d", &a, &b);
     printf("Actions:\n(A) Add\n(S) Subtract\n(D) Divide\n(M) Multiply\n");
     printf("Choice: ");
     c=getche();
     
     if (c=='A')
     {
      d=add(a, b);
      printf("The sum of %d and %d is %d", a, b, d);
      getch();
     }
     if (c=='S')
     {
      e=subtract(a, b);
      printf("The difference of %d and %d is %d", a, b, e);
      getch();
     }
     if (c=='D')
     {
      g=divide(a, b);
      printf("The quotient of %d and %d is %f", a, b, g);
      getch();
     }
     if (c=='M')
     {
      f=multiply(a, b);
      printf("The product of %d and %d is %d", a, b, f);
      getch();
     }
     getch();
    }
    int add(int a, int b)
    {
     return (a+b);
    }
    int subtract(int a, int b)
    {
     return (a-b);
    }
    int multiply(int a, int b)
    {
     return (a*b);
    }
    float divide(int a, int b)
    {
     return ((float)a/b);
    }
    GOOD LUCK

  3. #23
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    Quote Originally Posted by harryperales View Post
    do not use scanf when dealing with characters and strings kay naa jud cya tendency mo skip sa input nga part, resulta wala madawat nga value ang nag hulat sa output gkan sa scanf().
    getche() is another way to achieved, but allow me to introduced the advance way.

    try:

    scanf("%d%*[^\n]% %d%*[^\n]%", &a, &b);

  4. #24
    @harryperales: ok ra mn yata iyang function prototypes...

  5. #25
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    Quote Originally Posted by SmaRkieS View Post
    @xiao

    ambot asa ni gikan ani, ang gi input niya kay with spaces pero ang iyang gi pa output kay with comma, instead gi ingon samples sa TS kay with comma ang input, mas maayo if buhat nalang siya ug full program.
    The problem is that if you call scanf() to get some input, the newline is still left hanging around in the buffer and the rest of the characters. any leftover from stdin will be carried out on the next call.

    see my previous code for some sort of trick.

  6. #26
    already answered on my post #18

  7. #27
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    Quote Originally Posted by SmaRkieS View Post
    already answered on my post #18
    PHP Code:
     if (c=='D')
     {
      
    float e;
      
    g=divide(ab);
      
    printf("The quotient of %d and %d is %.2f"abg);
      
    getch();
     } 
    remove the line "float e;"

  8. #28
    gi compare na ko ang code ni smarkies ug TS... murag ang difference ra lagi kay sa TS kay void main(void) tapos kang smarkies kay main(void). hehe.. mao ra to? sakto ba ko smarkies?

  9. #29
    Yes xiao ako ra gi remove ang uban then gi balhin pud nako ang input sa 2 integers.. Running naman ang program tua sa gi post nako sa Post #18. Naa napud screen shots sa result.

  10. #30
    to TS, below is my take on your program. I'm not sure if this will run, but more or less, its the appropriate solution.

    TIPS
    *KISS(keep it short and simple)
    -avoid using too many variables
    -avoid using unnecessary functions
    -recycle variables if necessary

    PHP Code:
    #include <stdio.h>
    #include <conio.h>

    int main() {
      
    int ab;
      
    char c;
      
      
    clrscr();
      
    printf("Enter value for 1st number: ");
      
    scanf("%i",&a);
      
    printf("Enter value for 2nd number: ");
      
    scanf("%i",&b);
      
      
    printf("\nChoices:\n\t[A]ddition\n\t[S]ubtraction\n\t[M]ultiplication\n\t[D]ivision\nSelect: ");
      
    getche();
      
      if(
    c=='A'){
        
    printf("The sum of %i and %i is %i",ab, (a+b));
      }
      if(
    c=='S'){
        
    printf("The difference of %i and %i is %i",a,b,(a-b));
      }
      if(
    c=='M'){
        
    printf("The product of %i and %i is %i",a,b,(a*b));
      }
      if(
    c=='D'){
        
    printf("The quotient of %i and %i is %6.2f",a,b,(a/b));
      }
      
    getch();

    critic to your hearts content
    Last edited by ChaosOrb; 02-11-2010 at 03:29 PM.

  11.    Advertisement

Page 3 of 9 FirstFirst 123456 ... LastLast

Similar Threads

 
  1. Help me in my laptop problem
    By Wenxp7 in forum Computer Hardware
    Replies: 16
    Last Post: 10-08-2010, 07:48 PM
  2. pls help me in my pldt dsl connection...
    By glenntacan in forum Networking & Internet
    Replies: 5
    Last Post: 01-23-2009, 05:15 PM
  3. help me in my front panel config
    By absimon in forum Computer Hardware
    Replies: 5
    Last Post: 12-05-2008, 07:18 PM
  4. Please help me in martial arts.
    By Chalil in forum Sports & Recreation
    Replies: 11
    Last Post: 09-20-2006, 10:52 PM
  5. Where can I repair my flash drive?!!! Help me!!!
    By jonmlas in forum Gizmos & Gadgets (Old)
    Replies: 13
    Last Post: 11-30-2005, 12:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top