Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Chef has A units of solid and B units of liquid. He combines them to create a mixture. What kind of mixture does Chef produce: a solution, a solid, or a liquid?

A mixture is called a:

1) A solution if A>0 and B>0,

2) A solid if B=0, or

3) A liquid if A=0.

What I have tried:

C#
#include<stdio.h>
int main()
{
int A,G,L;
scanf("%d",&A);
while(A--)
{
scanf("%d%d",&G,&L);
if (A>0 && G>0)
printf("solution \n");
else if(G==0)
printf("solid \n");
else if(A==0)
printf("liquid \n");
}
return 0;
}
Posted
Updated 5-Oct-21 3:39am
v2

Read the question again, and try using the same variable names for the same purposes as the question does - it'll be a whole load clearer what is happening. (And point up some flaws in your code as well.)

In addition, indent your code: it makes it considerably more readable, even in a trivial app like this.
 
Share this answer
 
Quote:
How do I write program for this question for codechef challenge

Pay attention to variables usage. Be consistent.
C++
#include<stdio.h>
int main()
{
    int A,G,L;
    scanf("%d",&A);
    while(A--)
    {
        scanf("%d%d",&G,&L); // Here, the mix is G and L
        if (A>0 && G>0)      // Here L is now A
            printf("solution \n");
        else if(G==0)
            printf("solid \n");
        else if(A==0)        // Here L is now A
            printf("liquid \n");
    }
    return 0;
}


Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.

Indentation style - Wikipedia[^]
Best C++ Formatter and Beautifier[^]
Online C/C++ Formatter, Indenter and Beautifier – Techie Delight[^]

Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]
Enabling Open Innovation & Collaboration | The Eclipse Foundation[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900