Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 2 decades ago

這樣做有錯麼

#include <cstdlib>

#include <iostream>

using namespace std;

int main(int argc,char*argv)

{ float height;

float weight;

float a1;

float a2;

printf("請輸入身高(cm):");

scanf("%f",&height);

printf("請輸入體重(kg):");

scanf("%f",&weight);

a1=height/2.54;

a2=weight/2.2;

printf("你的身高為:%.2fcm\n",height);

printf("你的體重為:%.2fkg\n",weight);

printf("你的身高為:%.2f吋\n",a1);

printf("你的體重為:%.2f磅\n",a2);

system("PAUSE");

return EXIT_SUCCESS;

}

3 Answers

Rating
  • 2 decades ago
    Favorite Answer

    我剛用你寫的c core在VC++跑是沒有問題也都可以..我只將最後一行的return改為return 0及main部分改為int main()和拿掉一個include標頭檔,您試試看

    #include <iostream>

    using namespace std;

    int main()

    {

    float height;

    float weight;

    float a1;

    float a2;

    printf("請輸入身高(cm):");

    scanf("%f",&height);

    printf("請輸入體重(kg):");

    scanf("%f",&weight);

    a1=height/2.54;

    a2=weight/2.2;

    printf("你的身高為:%.2fcm\n",height);

    printf("你的體重為:%.2fkg\n",weight);

    printf("你的身高為:%.2f吋\n",a1);

    printf("你的體重為:%.2f磅\n",a2);

    system("PAUSE");

    return 0;

    }

    ===============================================================

    #include <iostream.h>

    int main()

    {

    float heigh;//因為身高有小數點,故宣告為小數型態變數hegiht

    float weight; //因為體重亦有小數點,故宣告為小數型態變數weight

    float inch,foot; //因為呎及吋等單位有小數點,故宣告為小數型態變數inch,foot

    float a2; //因為磅數單位有小數點,故宣告為小數型態變數a2

    printf("請輸入身高(cm):"); //於螢幕顯示"請輸入身高(cm)"

    scanf("%f",&height); //輸入至height變數裡並且輸入型態為小數點

    printf("請輸入體重(kg):"); //於螢幕顯示"請輸入體重(kg):"

    scanf("%f",&weight); //輸入至weight變數裡並且輸入型態為小數點

    inch=height/2.54;//1英吋=2.54cm

    foot=inch/12.0;//1呎=12吋

    a2=weight/2.2;

    printf("\n");//跳行

    printf("你的身高為:%.2fcm\n",height); //輸出height的值,並留小數點2位及跳行

    printf("你的體重為:%.2fkg\n",weight); //輸出weight的值,並留小數點2位及跳行

    printf("你的身高為:%.3f呎%.3f吋\n",foot,inch); //輸出呎,吋的值,並留小數點3位及跳行

    printf("你的體重為:%.2f磅\n",a2); //輸出a2的值,並留小數點2位及跳行

    system("PAUSE"); //系統暫停

    return 0; //因為前面的main宣告為int,故回傳一個整數值

    }

    2005-09-30 17:31:29 補充:

    那您可以補給我1公分的幾呎幾吋可以嗎??

    如1cm=2.54吋,1cm=幾呎?

    2005-09-30 17:32:45 補充:

    ps:因為我不知道換算單位,補給我可以幫你寫一寫

    Source(s): myself
  • Lv 7
    2 decades ago

    來晚了... :)

  • Anonymous
    2 decades ago

    一呎等於12吋1吋等於2.54公分如果ㄋ寫出來ㄌ可以幫我在計算程式作註解ㄇ謝謝

Still have questions? Get your answers by asking now.