您好我期待寫一個程序用於任意的三角形。 雖然我已經完成了我的任務的第一部分,即查找三角形是真還是假。我希望能夠使用用戶輸入的數據計算周長,然後計算三角形的面積。C++使用用戶輸入數據爲多種功能
但在計算周長時,它是相當龐大的數字。
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;
}
什麼是你的預期產出,什麼是現實? – xhg
15 + 15 + 32應該等於62 代替我得到19992646 –
這不是C.卸下'printf'和'scanf'東西和使用'的std :: cout'和'的std :: cin'。 –