Elijah Ceeney
Elijah Ceeney

Reputation: 25

c++ using user input data for multiple functions

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;
}

Upvotes: 0

Views: 229

Answers (1)

xhg
xhg

Reputation: 1885

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.

Upvotes: 1

Related Questions