guys i have really tried so many times but i can't just do it. can you help me?
guys i have really tried so many times but i can't just do it. can you help me?
> 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.
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
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.
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.
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; }
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.)
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
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.