Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
{
    int x,y;
    float z;
    printf("Write 2 integers: ");
    scanf("%d%d",&x,&y);

    switch (x && y)
    {
    case x+y>0 && x+y<=4:
        z = exp(x+y);
        printf("%f is an output.\n",z);
        break;
    
    
    case x+y==8 || x+y==10:
    z = (pow(x,2)+y)/(x-y);
    printf("%f is an output.\n",z);
    break;
    
    default:
        z = 0;
        printf("%f is an output.\n",z);
    }
    return 0;
}


What I have tried:

I tried to add If statement but i couldnt
Posted
Updated 12-Mar-16 7:13am
Comments
OriginalGriff 12-Mar-16 7:15am    
What problem?
All you have done is dumped your code on us, without telling use what it is supposed to do, much less what it does wrong!
What does it do that you didn't expect, or not do that you did?
How do you make it do it? What do you enter to cause the problem?
Use the "Improve question" widget to edit your question and provide better information.
Member 12378355we 12-Mar-16 13:14pm    
#include<stdio.h>
main()
{
int x,y,w; //Just add another variable
float z;
printf("Write 2 integers: ");
scanf("%d%d",&x,&y);
if((x+y==8 || x+y==10)) w=1;
if(x+y>0 && x+y<=4) w=0;

switch (w)
{
case 0:
z = exp(x+y);
printf("%f is an output.\n",z);
break;


case 1 :
z = (pow(x,2)+y)/(x-y);
printf("%f is an output.\n",z);
break;

default:
z = 0;
printf("%f is an output.\n",z);
}
return 0;
}

I think you didn't mean any hard jargon.....with the code?

Your case statements are not valid. Cases use constant values, not expressions. Your code should look like:
C++
int x,y;
float z;
printf("Write 2 integers: ");
scanf("%d%d",&x,&y);

if (x+y>0 && x+y<=4)
{
    z = exp(x+y);
}
else if (x+y==8 || x+y==10)
{
    z = (pow(x,2)+y)/(x-y);
}
else
    z = 0;

// you only need one printf at the end to print the value of z.
printf("%f is an output.\n",z);
 
Share this answer
 
Solution 1 gives you a probable correction of switch, but since you didn't tell us what it is supposed to do, we can't be sure.
Obviously, you don't know the usage of switch.
You should properly learn the language as soon as possible.
Advice:
- read language documentation, follow tutorials.
- The debugger is your friend. It will show you what your code is really doing.
Follow the execution step by step, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]
 
Share this answer
 
C++
#include<stdio.h>
main()
{
    int x,y,w; //ad another integar
    float z;
    printf("Write 2 integers: ");
    scanf("%d%d",&x,&y);
    if((x+y==8 || x+y==10)) w=1;//state condition 0
    if(x+y>0 && x+y<=4) w=0;//state condition 1

    switch (w) // replace here by w
    {
    case 0:      // replace here by w      
        z = exp(x+y);
        printf("%f is an output.\n",z);
        break;


    case 1 :   // replace here by w
    z = (pow(x,2)+y)/(x-y);
    printf("%f is an output.\n",z);
    break;

    default:
        z = 0;
        printf("%f is an output.\n",z);
    }
    return 0;
}
 
Share this answer
 
v3
Comments
Patrice T 13-Mar-16 0:55am    
This program is bugged

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