Hi all,
Im wondering if I can get some pointers.
I have an assignment for basic "c" programming , a reciprocal calculator with conditions.The conditions being : if entry =0 then print "reciprocal undefined" (this bit I can get!). else (should be) print "the reciprocal = 1/(number entered) or (decimal equivelent). (this bit is frying my head).
please help. this is what I have so far
// reciprocal calculator
// by jf
// date last modified 31/10/10
// include standard input/output from header file h
#include <stdio.h>
// include standard library from header file h
#include <stdlib.h>
// main function heading
main ()
// begining of instructions
{
// declare variables and set initial value to zero
float r=0,a=0,b=0;
// print on screen enter number
printf("Enter number:",&a); (this bit works ok)
// scan for input
scanf("%f",&b); (as does this)
// manipulate variables
r=(1/b); (not sure if im doing this bit right)
// if conditions
if (b==0) printf("Reciprocal undefined\n"); (this bit also works)
// otherwise do this
else printf("the reciprocal of,b,is = 1/,b,or %f\n",&r); ()mad!!!
// pause to view answer
system("PAUSE");
}
Im wondering if I can get some pointers.
I have an assignment for basic "c" programming , a reciprocal calculator with conditions.The conditions being : if entry =0 then print "reciprocal undefined" (this bit I can get!). else (should be) print "the reciprocal = 1/(number entered) or (decimal equivelent). (this bit is frying my head).
please help. this is what I have so far
// reciprocal calculator
// by jf
// date last modified 31/10/10
// include standard input/output from header file h
#include <stdio.h>
// include standard library from header file h
#include <stdlib.h>
// main function heading
main ()
// begining of instructions
{
// declare variables and set initial value to zero
float r=0,a=0,b=0;
// print on screen enter number
printf("Enter number:",&a); (this bit works ok)
// scan for input
scanf("%f",&b); (as does this)
// manipulate variables
r=(1/b); (not sure if im doing this bit right)
// if conditions
if (b==0) printf("Reciprocal undefined\n"); (this bit also works)
// otherwise do this
else printf("the reciprocal of,b,is = 1/,b,or %f\n",&r); ()mad!!!
// pause to view answer
system("PAUSE");
}
Last edited: