首页 > 解决方案 > 我正在使用 Visual Studio 2019,我目前正在用 C 语言制作一些关于身高和体重的方程式,这是否非常相似?

问题描述

我只想知道我是否犯了任何错误(考虑到我的代码中有 11 个警告和多条绿线,这很可能是这样。)

#include <stdio.h>
#include <conio.h>

int main(void) 

{

    int heightBody, weightBody, heightAndWeightResult; // Variables

    printf("Enter Body Weight: ", weightBody); //Manual Input
    scanf_s("%d", &weightBody);

    printf("Enter Body Height: ", heightBody);// Manual Input
    scanf_s("%d", &heightBody);

    heightAndWeightResult = heightBody + weightBody; // to calculate the height and weight
    printf("Body Result: ", heightAndWeightResult);

    getch();
    return 0;

}

关于错误消息,存在“参数过多”错误;使用未初始化的内存;和返回值忽略 getch();

标签: c

解决方案


  1. 给变量初始值

IE

int heightBody = 0, weightBody = 0, heightAndWeightResult;
  1. 检查返回值scanf_s- 阅读手册页

  2. 不需要前两个中的变量printf

IE

 printf("Enter Body Weight: "); 
 printf("Enter Body Height: ");
  1. 最后需要一个格式说明符printf

IE

 printf("Body Result: %d", heightAndWeightResult);

也许值得您阅读printfscanf_s


推荐阅读