All pastes #389764 Raw Edit

Miscellany

public c v1 · immutable
·published 2007-03-10 22:53 UTC
rendered paste body
#include <stdio.h>/* Replacement resistance. */int ohm_calc(float ampere, float volt, float ohm){	float result = 0;	if((ampere == 0) && (volt == 0) && (ohm == 0))	{		printf("You have to give at least two values.\n");	}	if(ampere == 0)	{		result = volt / ohm;		printf("Volt: %f\nOhm: %f\nAmpere: %f\n", volt, ohm, result);	}	if(volt == 0)	{		result = ohm * ampere;		printf("Volt: %f\nOhm: %f\nAmpere: %f\n", result, ohm, ampere);	}	if(ohm == 0)	{		result = volt / ampere;		printf("Volt: %f\nOhm: %f\nAmpere: %f\n", volt, result, ampere);	}	return 0;}/* Main function */int main(){	int which;	float volt, ampere, ohm;	int i;	int size;	float result = 0;	printf("What do you wanna calculate?\n0 = Ohm, Ampere or Voltage.\n1 = Replacement resistance. (Paralell)\n2 = Replacemnt Resistance (Serial)\n\n");	printf("Choose:_\b");	scanf("%d", &which);	switch(which)	{		case 0:			printf("Welcome. Give me the values of Ohm, Ampere and Voltage.\n");			printf("The one you set as 0 is the one that is going to be calculated.\n");			printf("Volt:_____\b\b\b\b\b");			scanf("%f", &volt);			printf("Ampere:_____\b\b\b\b\b");			scanf("%f", &ampere);			printf("Ohm:_____\b\b\b\b\b");			scanf("%f", &ohm);			ohm_calc(ampere, volt, ohm);			break;		case 1:			printf("Give me how many numbers you are going to use.\n");			printf("Size:__\b\b");			scanf("%d", &size);			float rr[size];			for(i = 0; i < size; ++i)			{				printf("Give me number %d:", i + 1);				scanf("%f", &rr[i]);				printf("You gave me %f\n", rr[i]);			}			for(i = 0; i < size; ++i)			{				result = result + (1 / rr[i]);			}			result = 1 / result;			printf("Result: %f\n", result);		break;		case 2:			printf("Give me how many numbers you are going to use.\n");			printf("Size__\b\b");			scanf("%d", &size);			for(i = 0; i < size; i++)			{				printf("Give me number %d:", i +1);				scanf("%f", &result);				result = result + result;			}			printf("Result: %f\n", result);		break;	}	return 0;}FEL:testing.c: In function 'main':testing.c:77: error: case label in scope of identifier with variably modified type not containing enclosing switch statement