-1 c
提出的问题是:"考虑下一个问题,创建一个计算2个月内能源消耗的问题:
我写了这个程序,当我运行它并添加浪费和小时的值时,无论我输入哪个值,费用都会给我0.00.
#include <stdio.h>
#include <math.h>
int main()
{
int c; //energy waste//
float p, h; // p=fee h=hours//
printf("Introduce el consumo y el numero de horas:");
scanf("%d %f ", &c, &h);
if (c<1000) {
p=h*1.2;
}
if ((c=1000) && (c<1851)) {
p=h*1.2;
}
if (c>1850) {
p=h*0.9;
}
printf("Fee: %f", p);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我需要收取费用.我希望它写得很好,因为我讲西班牙语并且不熟悉英语中的编程概念.
if ( ( c = 1000 ) && ( c < 1851 ) ) {
Run Code Online (Sandbox Code Playgroud)
应该
if ( ( c >= 1000 ) && ( c <= 1850 ) ) {
Run Code Online (Sandbox Code Playgroud)
你可能有一个拼写错误而=不是打字>
当你使用
if( ( c = 1000 ) && ( c < 1851 ) ){
Run Code Online (Sandbox Code Playgroud)
你要分配1000给c.