小编Pao*_*oMC的帖子

当用户在保存 float 变量的 scanf 中输入字符串时出现错误

我现在正在练习 C 编程,并且制作了一些 BMI 计算器。它工作得很好,但是当用户在第一个输入字符串或字符时scanf将数据发送到浮点变量 'weight' 。scanf之后一切都过去了,并向我显示错误Your BMI is 1.#J。如何解决这个错误?这是我的代码。

#include <stdio.h>

int main()
{
  float weight;
  float height;
  float result;
  float c_height;

  printf("Enter your weight as kilogram...\n\n> ");
  scanf("%f",&weight);
  //If user input char or string , it passed all thing and showed error.

  printf("\nEnter your height as centimetres...\n\n> ");
  scanf("%f",&height);

  c_height=(height/100)*(height/100);
  result=weight/c_height;

  if(result<18.50)
  {
    printf("\nYour BMI is %.2f\n\n",result);
    printf("You are underweight! Try to eat more frequently\n\n");
    printf("Thank you for using my program!\n\n");

}else …
Run Code Online (Sandbox Code Playgroud)

c codeblocks

1
推荐指数
1
解决办法
618
查看次数

解析错误:语法错误,意外的',',期望变量(T_VARIABLE)

我在定义函数和从 error_reporting(E_ALL);

有错误 Parse error: syntax error, unexpected ',', expecting variable (T_VARIABLE) in C:\xampp\htdocs\bs4\func.php on line 4

这是我的代码

<?php
error_reporting(E_ALL);
require_once "condb.php";
function noproblem(time,suggest,phone,eat,problem){ // Here is line 4

  $sql="insert into data(time,suggest,phone,eat,problem) values(?,?,?,?,?)";
  $stmt=$cn->prepare($sql);
  $stmt->bindParam("1",time);
  $stmt->bindParam("2",suggest);
  $stmt->bindParam("3",phone);
  $stmt->bindParam("4",eat);
  $stmt->bindParam("5",problem);

  try {
    $stmt->execute();
    echo "ok!";
  } catch (Exception $e) {
    echo $e->getTraceAsString();
  }
}
?>
Run Code Online (Sandbox Code Playgroud)

php pdo php-parse-error

-4
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1

codeblocks ×1

pdo ×1

php ×1

php-parse-error ×1