Originally Posted by
KingCabrera
Willing to pay someone who completes the code, and functions perfectly
Wow you're really in a hurry to pay people when you did most of the work...
Most of the problems I get from compiling are simple to fix.
Code:
gcc -Wall -std=c99 -ggdb -o Proj Proj.c
Proj.c: In function 'main':
Proj.c:50:4: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
if(choice1=1)
^
Proj.c:83:4: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
else if (choice1=2)
^
Proj.c:114:8: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
else if (choice1=3)
^
Proj.c:38:11: warning: unused variable 'pi' [-Wunused-variable]
float pi=3.14;
^
Proj.c:37:16: warning: unused variable 'D' [-Wunused-variable]
char A,B,C,D,choice2;
^
Proj.c:37:14: warning: unused variable 'C' [-Wunused-variable]
char A,B,C,D,choice2;
^
Proj.c:37:12: warning: unused variable 'B' [-Wunused-variable]
char A,B,C,D,choice2;
^
Proj.c:37:10: warning: unused variable 'A' [-Wunused-variable]
char A,B,C,D,choice2;
^
Proj.c:60:27: warning: 'result' may be used uninitialized in this function [-Wmaybe-uninitialized]
printf("the perimeter is: %f units", result);
^
Since you declared stuff that you aren't using, the simplest fix is to delete it (that is pi, A, B, C, and D on that line) and see what breaks.
The other problem is that when you make a comparison for equality, the proper way to write it is double equals (==). However in context, it looks like you have a bigger problem. choice1 comes from here:
Code:
float choice1, ...;
...
printf("\n dWhat would you like to calculate?\n\n1)perimeter\n2)area\n3)volume\n\n");
scanf("%f", &choice1);
I really don't think choice1 should be a float. It's just not the right type. If the user selects, say, 1, it is harder to compare the data in choice1 which may have rounding errors, to 1.0000 than you might think. So what do I mean by rounding errors. In effect, if choice1 actually contains 1.00036945 and you compare it to 1.0000000 and those don't look equal to you, that is the real problem.
The easiest fix is to just use an int for choice instead. It's a couple of statements to fix, but if you know what you're doing at all it isn't hard to do.
The problem with result being unused is a bit harder to explain but I will try. Basically, you keep writing lines like this, when you intend to call your functions:
Code:
double perSquare(float length);
...
double perRectangle(float length, float width);
...
double perTriangle(float sideA, float sideB, float sideC);
...
double perCircle(float radius);
These lines are sprinkled throughout the code in main() and they aren't going to do what you want. You need to write something like this and use the variables that you had the user enter instead:
Code:
result=perSquare(length)
...
result=perRectangle(length, width);
...
result=perTriangle(sideA, sideB, sideC);
...
result=perCircle(radius);
I hope that makes sense. But after all of this is fixed you will at least get a clean compile. Next we have a run of the program to see what is wrong. In fairness, it looks like perimeter is okay. I did a few test runs, and it worked. But area had an interesting problem:
Code:
C:\Users\jk\Downloads>Proj
Shape Calculator
dWhat would you like to calculate?
1)perimeter
2)area
3)volume
2
what shape?
A)square
B)rectangle
C)triangle
D)circle
C:\Users\jk\Downloads>
Wow, by the time I was ready to type, the program ended! I had a look at what was different.
Code:
if(choice1==1)
{
printf("what shape?\n\nA)square\nB)rectangle\nC)triangle\nD)circle\n\n");
while (getchar() !='\n');
scanf("%c", &choice2);
Choosing 1 is different from the rest. There is that extra loop on that one line that actually gets rid of extra \n and allow you to type for scanf. I moved it up before the if, so that it will have that effect for every choice.
With a few minor spacing improvements, it seemed like it worked okay. I'm attaching the file with these changes, as it seems like you have more work to do.