0

Hi i am looking to write a program for a arbitrary triangle. Whilst i have completed the first part of my task which is to find if the triangle is either true or false. i want to be able to use the data inputted by the user to calculate the perimeter then eventually the area of the triangle.

But when the perimeter is calculated it is rather huge number.

This is my code so far.#include "stdafx.h"
#include "math.h"

    enter code here

// ConsoleApplication6.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "math.h"

/* enter three variables a, b ,c to create a triangle*/
int main()
{
    double a;   /*insert dimensions of side a*/
    double b;   /*insert dimensions of side b*/
    double c;   /*insert dimensions of side c*/
    double p;   /*variable for the perimeter of a triangle*/
    double s;   /*variable for the area of a triangle*/

    /* Get the user to enter the dimensions of a*/
    printf_s("enter the  dimensions of a: ");   
    scanf_s("%d", &a);                          

    /* Get the user to enter the dimensions of b*/
    printf_s("enter the  dimensions of b: ");   
    scanf_s("%d", &b);
    /* Get the user to enter the dimensions of c*/
    printf_s("enter the  dimensions of c: ");   
    scanf_s("%d", &c);                          

    /* Conditions of a triangle*/
    if ("a + b > c && a + c > b && b + c > a")  

        printf_s("True\n");     /* Display True if able to make a triangle*/

    else printf_s("False\n"); /* Display false if unable to make a triangle*/

    double p = a + b + c;   

    /*Scan user input data a, b, c*/
    scanf_s("%d", &a, "%d", &b, "%d", &c);

    /*output total perimeter*/
    printf_s("The perimeter of the triangle is: ""%d, p");  





    return 0;
}
4
  • What's your expected outputs and what's the reality? Commented Apr 9, 2017 at 9:12
  • 15 + 15 + 32 should equal 62 instead i get 19992646 Commented Apr 9, 2017 at 9:20
  • This is not C. Remove the printf and scanf stuff and use std::cout and std::cin. Commented Apr 9, 2017 at 10:34
  • @ChristianHackl my class requires i use printf and scanf. Commented Apr 10, 2017 at 4:56

1 Answer 1

1

The problems is that all %d should be replaced by %lf in order to match the type double.

And also remove the line scanf_s("%d", &a, "%d", &b, "%d", &c);, once you scan once, you cannot scan again to get the same value.

Sign up to request clarification or add additional context in comments.

4 Comments

i have changed all the %d to %lf and now i receive 0.0000 i also only want to input this data only once instead of doing it a again.
@ElijahCeeney remove the line scanf_s("%d", &a, "%d", &b, "%d", &c);,
Thank you Im still getting the issue of perimeter equaling 0.000 instead of a + b + c.
@ElijahCeeney It is because your program also contains a lot of typos: for example: printf_s("The perimeter of the triangle is: ""%d, p"); should be printf_s("The perimeter of the triangle is: %d", p);; if ("a + b > c && a + c > b && b + c > a") should be if (a + b > c && a + c > b && b + c > a). You need to learn and practice more to avoid this kinds of errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.