Search In
• More options...
Find results that contain...
Find results in...

# Case function in C

case (argument): things to do until break;

ie.

case a<b : print out "hello"; break;

so in your example, you're comparing variable 'y' to see if it's an character 'A', 'B', 'C', 'D', or 'F', you're not comparing it to see if the value is larger or smaller than certain things.

as for the rest of your program, no idea

## Recommended Posts

Posted · Original PosterOP

Hi im having trouble getting my case function to work. I enter a number between 0-60 and it is meant to return a @your number is greater than x but less than y. It has to be done with switch statemtents but i dont know how to make this function. I am incrementing my for loop and trying to get it to work that way. Any ideas?

```	#include <stdio.h>
void main(void)
{
int y;
double x, a, b, c, result;

printf("Enter value for y: \n");
scanf_s("%lf", &y);
getchar();

int counter;
int min;
int max;
for (counter = 0; counter < 6; counter++) { // Incraments if statments up to 60
min = counter * 10;						// Multiplys counter by 10
max = (counter + 1) * 10;				// Allows counter up to 60
if (y >= min && y < max)				// If statement for if its between 0<60
{
switch (y) {
case 'A':
printf("y is equal or greater than %d and smaller than %d", min, max);
break;

case 'B':
printf("y is equal or greater than %d and smaller than %d", min, max);
break;

case 'C':
printf("y is equal or greater than %d and smaller than %d", min, max);
break;

case 'D':
printf("y is equal or greater than %d and smaller than %d", min, max);
break;

case 'F':
printf("y is equal or greater than %d and smaller than %d", min, max);
break;
default:
printf("Invalid number\n");
}
}
}

printf("\n Enter value for X:");	//Gets vlaue for x
scanf_s("%lf", &x);				//Reads in value for x
getchar();						//Waits for input
printf("Enter value for A:");
scanf_s("%lf", &a);
getchar();
printf("Enter value for B:");
scanf_s("%lf", &b);
getchar();
printf("Enter value for C:");
scanf_s("%lf", &c);
getchar();

result = (a * pow(x, 2)) + (b * x) + c;
}```

##### Share on other sites

case (argument): things to do until break;

ie.

case a<b : print out "hello"; break;

so in your example, you're comparing variable 'y' to see if it's an character 'A', 'B', 'C', 'D', or 'F', you're not comparing it to see if the value is larger or smaller than certain things.

as for the rest of your program, no idea

Things I need help with: *new* What can Facebook do to me? Privacy Inquiries

Spoiler

I hate Intel's pricing, Ryzen's weird quirks, Nvidia's pricing, and Radeon GPUs in general

Spoiler

Products I like:

Spoiler

Sony Xperia Z1 / Z2 / 10 ii, Asus Strix 970 / 1070, Samsung SSD, WD HDD, Corsair PSUs (AX, RM, CX(grey)), GeForce GPU, NZXT N450/S340, be quiet! Coolers, G.Skill Trident RAM, Logitech M525, Logitech G440, Razer Deathadder Elite

Products I hate:

Spoiler

Xperia Z3, XiaoMi 5c, Radeon GPUs, Razer Audio Products, any bloatwares

Companies I absolutely adore: (and hope it stays that way)

Spoiler

be quiet! - sent me AM4 mounting for my DRP3 even though it's way past the timeframe stated, no questions asked

Corsair - very good RMA experience, absolutely recommend

Companies I hate:

Spoiler

Nvidia, Intel, Apple, TMT (Thundermatch, a retailer)

Personal Blacklisted Companies:

Spoiler

Acer: shit tier quality products, shit tier customer service thus far, they "tried" to solve my issue but they arent really doing anything but delaying and delaying. (on-going case since July)

Gigabyte: horrible customer service (gigabyte had literally 0 customer service, asked me to go to retailer with NO WAY to email them about a question) but at least they fixed my shit in ONE MONTH (would probably take me 1 hour to fix if they let me email them)

XiaoMi Phones: built like a tank but the software is buggy as all hell

Kingston SSD: 300V controller swap thingy

Razer (except their mouse)

Remember, just because I had good/bad experiences with these companies/product, doesn't mean you will have similar experiences too. I would still recommend these products if they made sense for your needs, but I'll add a disclaimer of my experience if it's relevant. Feel free to DM me asking why they are where they are.