Thread: i need help please help me

  1. #1
    Registered User
    Join Date
    Oct 2018
    Posts
    8

    i need help please help me

    guys i have really tried so many times but i can't just do it. can you help me?
    Attached Images Attached Images i need help please help me-sa-jpg 

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,685
    > guys i have really tried so many times
    So post one of your better attempts, and we'll help you figure out where you went wrong.
    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
    Oct 2018
    Posts
    8
    despite the fact that i have tried so many times. i couldn't manage to make an improvement. i just can't understand how we can define x as maximum function. for example if we just write the input as 5 6 7 8 x the output will be 8 if you can just explain one of them(max min sum or average) i think i can handle the rest. i hope i can

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,685
    At least post your program to read in 4 numbers.
    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.

  5. #5
    Registered User
    Join Date
    Oct 2018
    Posts
    8
    Quote Originally Posted by Salem View Post
    At least post your program to read in 4 numbers.
    i need help please help me-screenshot-2018-10-16-20-43-17-jpg

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,685
    Ok so far.

    Can you also read the last character using %c

    What about an if statement
    if ( ch == 'x' )

    Also, please post your code between [code][/code] tags. Fuzzy pictures just don't cut it.
    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.

  7. #7
    Registered User
    Join Date
    Oct 2018
    Posts
    8
    Quote Originally Posted by Salem View Post
    Ok so far.

    Can you also read the last character using %c

    What about an if statement
    if ( ch == 'x' )

    Also, please post your code between tags. Fuzzy pictures just don't cut it.
    Code:
    #include<stdio.h>
    int main()
    {
    int p,q,r,t;
    char x,m,s,a;
    scanf("%d %d %d %d %c",&p,&q,&r,&t,&x);
      if(p>q) 
            { 
                 if(p>r) 
                  { 
                     if(p>t) 
                      {   
                         printf("%d ",p); 
                       } 
                     else 
                      { 
                         printf("%d ",t); 
                       } 
                   } 
              } 
                  else if(q>r) 
                          { 
                               if(q>t) 
                                 { 
                                     printf("%d ",q); 
                                  } 
                                else 
                                 { 
                                     printf("%d",t); 
                                 } 
                           } 
                   else if(r>t) 
                          { 
                                 printf("%d ",r); 
                           } 
                  else 
                   { 
                        printf("%d ",t); 
                         
                   } 
    return 0;
    }

  8. #8
    Registered User
    Join Date
    Oct 2018
    Posts
    8
    Quote Originally Posted by Salem View Post
    Ok so far.

    Can you also read the last character using %c

    What about an if statement
    if ( ch == 'x' )

    Also, please post your code between tags. Fuzzy pictures just don't cut it.
    i think i was able to make the maximum part of the question. but i don't know how to continue after this

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Well, but you're always doing the maximum (at least with what you posted), instead of checking what you're supposed to be doing. You'll need to make a decision about what to do based on the character you read in. (Given that this is homework, you will almost certainly have just gone over something relevant to the problem, so you may want to review your notes.)

  10. #10
    Registered User
    Join Date
    May 2009
    Posts
    3,749
    If you have learned arrays, I would suggest you use one to solve the problem.

    If you have learned switch statements, I would suggest you use one to solve the problem.

    If you have learned for loops, I would suggest you use one to solve the problem.

    If you have learned for loops and arrays, I would maybe only use one of them to solve the problem.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,685
    Do you know about functions yet?

    Consider writing functions to do specific tasks.

    Such as
    m = max(p,q);
    m = max(r,max);
    m = max(t,max);

    The function only has to deal with two numbers, so it's really easy to determine which is the largest.
    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.

Popular pages Recent additions subscribe to a feed

Tags for this Thread