-------------------------------------------------------------------------------------------
CODE
//Ryan Quick
//Ohm's Law
#include <stdio.h>
#include <math.h>
#include <time.h>
void stuff ();
void main ()
{
stuff ();
}
void stuff ()
{
//Local Declaration
char unknown;
double a,b,answer;
int c,d,e;
//Statements
printf("\n\nNote: Be sure to use standard units for all calculations.\n");
printf("When asked yes or no questions, answer 1 for yes and 0 for no.\n");
printf("What do you want to solve for?\n v = voltage \n i = current \n r = resistance \n p = power\n");
scanf("%c", &unknown);//What you want to solve for?
//Solving for Voltage
if(unknown == 'v')
{
printf("Do you know current?\n");
scanf("%d", &c);
if(c == 1)
{
printf("Do you know resistance?\n");
scanf("%d", &d);
if(d == 1)
{
printf("What is the current?\n");
scanf("%lf", &a);
printf("What is the resistance?\n");
scanf("%lf", &b);
answer = a * b;
printf("%lf Volts\n", answer);
}
if(d == 0)
{
printf("What is the current?\n");
scanf("%lf", &a);
printf("What is the power?\n");
scanf("%lf", &b);
answer = b/a;
printf("%lf Volts\n", answer);
}
}
if(c == 0)
{
printf("What is the resistance?\n");
scanf("%lf", &a);
printf("What is the power?\n");
scanf("%lf", &b);
answer = sqrt(a * B);
printf("%lf Volts\n", answer);
}
}
//Solving for Current
if(unknown == 'i')
{
printf("Do you know voltage?\n");
scanf("%d", &c);
if(c == 1)
{
printf("Do you know resistance?\n");
scanf("%d", &d);
if(d == 1)
{
printf("What is the voltage?\n");
scanf("%lf", &a);
printf("What is the resistance?\n");
scanf("%lf", &b);
answer = a / b;
printf("%lf Amperes\n", answer);
}
if(d == 0)
{
printf("What is the voltage?\n");
scanf("%lf", &a);
printf("What is the power?\n");
scanf("%lf", &b);
answer = b/a;
printf("%lf Amperes\n", answer);
}
}
if(c == 0)
{
printf("What is the resistance?\n");
scanf("%lf", &a);
printf("What is the power?\n");
scanf("%lf", &b);
answer = sqrt(b/a);
printf("%lf Amperes\n", answer);
}
}
//Solving for Resistance
if(unknown == 'r')
{
printf("Do you know voltage?\n");
scanf("%d", &c);
if(c == 1)
{
printf("Do you know current?\n");
scanf("%d", &d);
if(d == 1)
{
printf("What is the voltage?\n");
scanf("%lf", &a);
printf("What is the current?\n");
scanf("%lf", &b);
answer = a / b;
printf("%lf Ohms\n", answer);
}
if(d == 0)
{
printf("What is the voltage?\n");
scanf("%lf", &a);
printf("What is the power?\n");
scanf("%lf", &b);
answer = a * a / b;
printf("%lf Ohms\n", answer);
}
}
if(c == 0)
{
printf("What is the current?\n");
scanf("%lf", &a);
printf("What is the power?\n");
scanf("%lf", &b);
answer = (B) / (a*a);
printf("%lf Ohms\n", answer);
}
}
//Solving for Power
if(unknown == 'p')
{
printf("Do you know voltage?\n");
scanf("%d", &c);
if(c == 1)
{
printf("Do you know current?\n");
scanf("%d", &d);
if(d == 1)
{
printf("What is the voltage?\n");
scanf("%lf", &a);
printf("What is the current?\n");
scanf("%lf", &b);
answer = a * b;
printf("%lf Watts\n", answer);
}
if(d == 0)
{
printf("What is the voltage?\n");
scanf("%lf", &a);
printf("What is the resistance?\n");
scanf("%lf", &b);
answer = a * a / b;
printf("%lf Watts\n", answer);
}
}
if(c == 0)
{
printf("What is the current?\n");
scanf("%lf", &a);
printf("What is the resistance?\n");
scanf("%lf", &b);
answer = a * a * b;
printf("%lf Watts\n", answer);
}
}
main ();
}
//Ohm's Law
#include <stdio.h>
#include <math.h>
#include <time.h>
void stuff ();
void main ()
{
stuff ();
}
void stuff ()
{
//Local Declaration
char unknown;
double a,b,answer;
int c,d,e;
//Statements
printf("\n\nNote: Be sure to use standard units for all calculations.\n");
printf("When asked yes or no questions, answer 1 for yes and 0 for no.\n");
printf("What do you want to solve for?\n v = voltage \n i = current \n r = resistance \n p = power\n");
scanf("%c", &unknown);//What you want to solve for?
//Solving for Voltage
if(unknown == 'v')
{
printf("Do you know current?\n");
scanf("%d", &c);
if(c == 1)
{
printf("Do you know resistance?\n");
scanf("%d", &d);
if(d == 1)
{
printf("What is the current?\n");
scanf("%lf", &a);
printf("What is the resistance?\n");
scanf("%lf", &b);
answer = a * b;
printf("%lf Volts\n", answer);
}
if(d == 0)
{
printf("What is the current?\n");
scanf("%lf", &a);
printf("What is the power?\n");
scanf("%lf", &b);
answer = b/a;
printf("%lf Volts\n", answer);
}
}
if(c == 0)
{
printf("What is the resistance?\n");
scanf("%lf", &a);
printf("What is the power?\n");
scanf("%lf", &b);
answer = sqrt(a * B);
printf("%lf Volts\n", answer);
}
}
//Solving for Current
if(unknown == 'i')
{
printf("Do you know voltage?\n");
scanf("%d", &c);
if(c == 1)
{
printf("Do you know resistance?\n");
scanf("%d", &d);
if(d == 1)
{
printf("What is the voltage?\n");
scanf("%lf", &a);
printf("What is the resistance?\n");
scanf("%lf", &b);
answer = a / b;
printf("%lf Amperes\n", answer);
}
if(d == 0)
{
printf("What is the voltage?\n");
scanf("%lf", &a);
printf("What is the power?\n");
scanf("%lf", &b);
answer = b/a;
printf("%lf Amperes\n", answer);
}
}
if(c == 0)
{
printf("What is the resistance?\n");
scanf("%lf", &a);
printf("What is the power?\n");
scanf("%lf", &b);
answer = sqrt(b/a);
printf("%lf Amperes\n", answer);
}
}
//Solving for Resistance
if(unknown == 'r')
{
printf("Do you know voltage?\n");
scanf("%d", &c);
if(c == 1)
{
printf("Do you know current?\n");
scanf("%d", &d);
if(d == 1)
{
printf("What is the voltage?\n");
scanf("%lf", &a);
printf("What is the current?\n");
scanf("%lf", &b);
answer = a / b;
printf("%lf Ohms\n", answer);
}
if(d == 0)
{
printf("What is the voltage?\n");
scanf("%lf", &a);
printf("What is the power?\n");
scanf("%lf", &b);
answer = a * a / b;
printf("%lf Ohms\n", answer);
}
}
if(c == 0)
{
printf("What is the current?\n");
scanf("%lf", &a);
printf("What is the power?\n");
scanf("%lf", &b);
answer = (B) / (a*a);
printf("%lf Ohms\n", answer);
}
}
//Solving for Power
if(unknown == 'p')
{
printf("Do you know voltage?\n");
scanf("%d", &c);
if(c == 1)
{
printf("Do you know current?\n");
scanf("%d", &d);
if(d == 1)
{
printf("What is the voltage?\n");
scanf("%lf", &a);
printf("What is the current?\n");
scanf("%lf", &b);
answer = a * b;
printf("%lf Watts\n", answer);
}
if(d == 0)
{
printf("What is the voltage?\n");
scanf("%lf", &a);
printf("What is the resistance?\n");
scanf("%lf", &b);
answer = a * a / b;
printf("%lf Watts\n", answer);
}
}
if(c == 0)
{
printf("What is the current?\n");
scanf("%lf", &a);
printf("What is the resistance?\n");
scanf("%lf", &b);
answer = a * a * b;
printf("%lf Watts\n", answer);
}
}
main ();
}