C言語で表を作りたかった
auです。
今回はプログラムを組んでみました。
結論から言うとうまくいきませんでした。
#include <stdio.h> #include <string.h> #include <stdlib.h> int main(void) { int n = 0; // 件数 int total = 0; // 合計売上 int sale; // 売上 int sale_t[128]; // 売上テーブル double per; char emp[256]; // 従業員 char emp_t[256][30]; // 従業員テーブル printf("従業員名がendで終了する\n"); printf("%d人目の従業員名: ", n+1); scanf("%s", emp); printf("%sの売上: ", emp); scanf("%d", &sale); while (strcmp(emp, "end") != 0) { total += sale; n++; sale_t[n] = total; strcpy(emp_t, emp); printf("%d人目の従業員名: ", n); scanf("%s", emp); if (strcmp(emp, "end") != 0) { printf("%sの売上: ", emp); scanf("%d", &sale); } } n++; sale_t[n] = total; strcpy(emp_t, emp); printf("__________\n"); printf("担当者 売上 比率\n"); printf("--------------------\n"); for (int i = 1; i <= n; i++) { per = (double)sale_t[i] * 100.0 / (double)total; printf("%s %d %lf\n", emp_t[i], sale_t[i], per); } printf("=================\n"); return 0; } // 実行結果 従業員名がendで終了する 1人目の従業員名: a aの売上: 300 1人目の従業員名: b bの売上: 500 2人目の従業員名: c cの売上: 800 3人目の従業員名: end __________ 担当者 売上 比率 -------------------- 300 18.750000 800 50.000000 1600 100.000000 1600 100.000000 =================
担当者名がでてこないのとどこか計算を間違えたみたいです。
修正できるように勉強します。