//★の部分に文を加えて完成させる問題です。
実行結果は
Input x=0
Input y=0
Input x=2
Input y=1
Input x=1
Input y=3
Input x=-1
Input y=-1
(0.00,0.00)-(2.00,1.00)-(1.00,3.00)=4.47
のようにしたいです。
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<math.h>
//マクロ定義
#define MAXSIZE 30
#define LIST_TAIL-1
//二次元座標データを扱うための構造体の定義
struct POINT {
double x,y;
};
//データ型(構造体PINT)の抽象化
typedef struct POINT LIST_ITEM;
//データ型(int)の抽象化
typedef int LIST_POS;
LIST_ITEM list[MAXSIZE];
LIST_POS tail;
//Init関数リストを空にする
void Init(void) {
tail = 0;
}
//Top関数リストの先頭位置を返却する
LIST_POS Top(void) {
return 0;
}
//Next 関数リストの次の要素位置を返却する
LIST_POS Next(LIST_POS pos) {
if (pos < tail - 1) {
return pos + 1;
}
else {
return LIST_TAIL;
}
}
//Item関数リスト内の位置を指定して、その要素を返却する
LIST_ITEM Item(LIST_POS pos) {
if ((pos >= 0) && (pos < tail)) {
return list[pos];
}
else {
LIST_ITEM ret = { 0,0 };
return ret;
}
}
//Add関数リストの末尾に要素を追加する
void Add(LIST_ITEM value) {
if (tail < MAXSIZE) {
list[tail] = value;
tail++;
}
}
int main(void) {
//変数の宣言
LIST_ITEM n, pt1, pt2;
LIST_POS p;
double sum = 0;
//リストの初期化
//★
//2次元座標をリスト配列の要素に追加(Add)していく
while (1) {
printf("Input x="); scanf("%lf", &n.x);
printf("Input y="); scanf("%lf", &n.y);
if (n.x < 0 || n.y < 0)break;
Add(n);
}
//リストの先頭から内容(Item)を取り出して表示(printf)しつつ、2点間の距離(pt1,pt2)を合算していく
//★
//合算値を表示する
printf("=%.2f\n", sum);
return 0;
}