我现在正在练习 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) 我在定义函数和从 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)