Thread: Need help completing final project

  1. #1
    Registered User
    Join Date
    Apr 2016
    Posts
    4

    Exclamation Need help completing final project

    Hey Everyone, new to the board, but I'm currently struggling to finish my final code for my C Programming class. First time taking a programming class, and its going alright, some bumps on the way but fairly fine.

    Here are the instructions that were given.
    DESCRIPTION
    You are required to write a C program that will calculate the following:
    Perimeter: Square, Rectangle, Triangle, Circle.
    Area: Square, Rectangle, Triangle, Circle.
    Volume: Cube, Rectangular Prism, Triangular Pyramid, Sphere.

    DETAILS
    - Your program must allow the user to choose whether they want to calculate the Perimeter, Area orVolume. Provide a menu.
    - Once theyíve chosen their calculation from the Perimeter, Area or Volume menu your program mustprovide a menu with the available geometric shapes in the corresponding option. You must provide amenu again.
    - Your program must ask the user for the appropriate measurements needed to perform the calculations.Donít forget to validate the userís input.
    - Make sure that user knows the units in which the calculations are performed and display the units in thefinal result. You are free to use your own measuring units.
    - Your program should print the result of the calculations to 2 decimal places. Make sure that yourformulae use the correct data type to give the correct result.
    - The user must be able to make as many calculations as he wishes.
    - Your program must include at least: one switch statement, repetition structures, and if/elsestatements.
    - Your program must have the following 4 user defined functions:
    - void Menu(void); //displays a menu to the user
    - double perimeterSquare(float length); //returns the perimeter of a square with a given length
    - double areaSquare(float length); //returns the area of a square with a given length
    - double volumeSquare(float length); //returns the volume of a square or cube with a given length
    - You will add at least 3 more user defined functions.
    - Your source code must be readable and maintainable as possible by including meaningful comments,proper indentation, meaningful variable identifiers, constants, etc.
    - Your program must be user friendly, this includes readability of results and prompts.
    -- WHAT TO SUBMIT
    You must submit the source file (Calculator.c) through the class website.
    -- EXAMPLE OF OUTPUT
    This program calculates the Perimeter, Area, and Volume of geometrical figures.
    Menu
    1) Perimeter
    2) Area
    3) Volume
    - What would you like to calculate?
    User choice: 1
    - What geometrical figure would you like to use for Perimeter?
    1) Square
    2) Rectangle
    3) Triangle
    4) Circle
    User choice: 2
    Please enter the following values in meters.
    Length: - 0.25
    ERROR: The value of Length must be a positive value. Please try again.
    Length: 0.25
    Width: 0.50
    - The perimeter of the rectangle is: 1.50 m
    Would you like to make another Perimeter calculation (1 for Yes, 2 for No)? 1
    What geometrical figure would you like to use for Perimeter?
    1) Square
    2) Rectangle
    3) Triangle
    4) Circle
    User choice: 1
    Please enter the following values in meters:
    Length: 0.3
    The perimeter of the square is: 1.20 mWould you like to make another Perimeter calculation (1 for Yes, 2 for No)? 2
    Would you like to go back to the Main PAV menu (1 for Yes, 2 for No)? 1
    Menu
    1) Perimeter
    2) Area
    3) Volume
    - What would you like to calculate?
    User choice: 2
    Which geometrical figure would you like to use for Area?
    1) Square
    2) Rectangle
    3) Triangle
    5) Circle
    User choice: 1
    Please enter the following values in meters:
    Length: 2.5
    The area for the square is 6.25 m^2
    Would you like to make another Perimeter calculation (1 for Yes, 2 for No)? 2
    Would you like to go back to the Main PAV menu (1 for Yes, 2 for No)? 2
    ****** Thank you for using this calculator. Goodbye. ******


    I've attached my code so far in the attachments. Currently stuck and have no clue what to do. Any corrections or guidance will be greatly appreciative.
    The project is due on Monday April 18, 2016 at 11:55pm EST
    Please help me finish this class with either an A OR B.
    THANK YOU AGAIN

    If needed to get in contact with me my email << nobody cares what your email is >>

    Thank you
    Attached Files Attached Files
    Last edited by KingCabrera; 04-14-2016 at 08:28 PM.

  2. #2
    Registered User
    Join Date
    Apr 2016
    Posts
    4
    Willing to pay someone who completes the code, and functions perfectly

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,360
    It is a class. You should not cheat by paying or otherwise persuading people to your work for you.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Jun 2015
    Posts
    1,643
    Quote Originally Posted by laserlight View Post
    It is a class. You should not cheat by paying or otherwise persuading people to your work for you.
    Offering to pay and posting his email address just seems wrong, maybe against the rules.
    Could you delete his email address at least? Or cancel the account?

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,616
    Quote Originally Posted by KingCabrera View Post
    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.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    Apr 2016
    Posts
    4
    I appreciate the help, now i have to figure out how to add a loop so it''ll go back to the main menu after it completes 1 function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Final project
    By albireo in forum C++ Programming
    Replies: 4
    Last Post: 05-01-2014, 07:07 PM
  2. Replies: 4
    Last Post: 10-19-2013, 11:01 PM
  3. ideas for a final project
    By doubleanti in forum General Discussions
    Replies: 11
    Last Post: 09-09-2012, 08:00 AM
  4. Must be final project time again....
    By VirtualAce in forum General Discussions
    Replies: 21
    Last Post: 05-19-2010, 07:04 PM
  5. Final year project
    By khpuce in forum A Brief History of Cprogramming.com
    Replies: 22
    Last Post: 10-10-2003, 07:04 AM