Also schreibe ich ein Engineering-Programm für meine ENGR200-Klasse und ich bin fest stecken. Ich habe noch nie eine Programmiersprache gelernt, aber ich habe das Web für die letzten 3 Stunden durchforstet und jede Variation von Loops getestet, und ich kann scheinbar nichts zur Arbeit bringen.While-Schleife weiter, wenn Bedingung erfüllt
Was will ich das Programm zu tun ist,
- eine Benutzereingabe
- Test erhalten, wenn sie in einem akzeptablen Bereich liegt
- wenn es nicht ich es will eine Fehlermeldung senden
- zur Eingabe eines neuen Eintrags
- Wenn es den akzeptablen Bereich erfüllt, möchte ich es auf den Rest fortsetzen.
Mein aktueller Code ist unten:
/*******************************************************************************
AUTHOR SECTION
ENGR 200.xx DATE: mm/dd/yyyy
PROGRAM: # Author:
********************************************************************************
PROGRAM DESCRIPTION
This program will allow the user to enter the temperature in fahrenheit
and relative humidity in percent. Then ask the user wether he/she will be in
direct sun. Next, if an unacceptable temp or relative humidiy is entered, an
error message should be printed. If the error check is passed, the program
will then calculate the heat index and humidex. The program will then print
these values temp in degrees fahrenheit, the temperature in degree celsius,
the relative humidity, the heat index, and the humidex. Based on the heat
index value the program will prin and appropriate warning below the output.
If heat index is below 80F print "No health concerns expected."
DESCRIPTION OF VARIABLES
NAME TYPE DESCRIPTION
heat_index double Calculated value for heat index
humi_index double Calculated value for humidex
humi_f double Calculated variable used in humi_index
temp int User input for degrees fahrenheit
temp_c double Calculated value for conversion f --> C
relat_humid int User input of relative humidity in % [0-100]
humi_pow double power value for humi_f calculation
direct_sun char User input for direct sun contact or not
heat_index_y double heat_index + 15
humi_index_y double humi_index + 9
-----------------------------------------------------------------------------
FORMULAS
humi_pow = (((7.5)*(temp_c))/((237.7)+(temp_c)))
heat_index =
(-42.379)+(2.04901523*temp)+
(10.14333127*relat_humid)-
(0.22475541*temp*relat_humid)-
((6.83783*(pow(10,-3)))*(pow(temp),2))-
((5.481717*(pow(10,-2)))*(pow(relat_humid,2)))+
((1.22874)*(pow(10,-3))*(pow(temp,2))*(relat_humid))+
((8.5282)*(pow(10,-4))*(temp)*(pow(relat_humid,2)))-
((1.99*(pow(10,-6))*(pow(temp,2))*(pow(relat_humid,2)))
humi_f =
((6.112)*(pow(10,humi_pow)))*((relat_humid)/100.0)
humi_index =
(temp_c+((5.0/9.0)*(humi_f-10)))
*******************************************************************************/
/* Preprocessor directives */
#include <stdio.h>
#include <math.h>
/* Main function */
int main()
{
/* Declare variables */
char direct_sun;
double heat_index, humi_index, temp_c, humi_pow, humi_f, humi_index_y,
heat_index_y, temp, relat_humid;
/* Print headings */
printf("********************************************");
printf("\n APPARENT HEAT CALCULATION");
/* Input values */
printf("\n\nEnter temperature in degrees Fahrenheit: ");
scanf("%d",&temp);
/* Check valididty of temp */
while(temp < 67)
{
printf("You must input a value greater than 67 degrees fahrenheit.");
printf("\nEnter temperature in degrees Fahrenheit: ");
scanf("%d",&temp);
if(temp >= 67)
{
break;
}
}
printf("Enter relative humidity (56% as 56) : ");
scanf("%d",&relat_humid);
/* Check validity of relat_humid */
while(relat_humid <= 0 || relat_humid >= 100)
{
printf("You must input a value between 0 and 100.");
printf("\nEnter relative humidity (56% as 56) :");
scanf("%d",&relat_humid);
if(relat_humid <= 100 && relat_humid >= 0)
{
break;
}
}
printf("Working in direct sun (y/n)? : ");
scanf("%c",&direct_sun);
/* Compute */
temp_c = ((5.0/9.0)*(temp-32));
humi_pow = (((7.5)*(temp_c))/((237.7)+(temp_c)));
humi_f = ((6.112)*(pow(10,humi_pow)))*((relat_humid)/100.0);
humi_index = (temp_c+((5.0/9.0)*(humi_f-10)));
heat_index =
(-42.379)+(2.04901523*temp)+
(10.14333127*relat_humid)-
(0.22475541*temp*relat_humid)-
((6.83783*(pow(10,-3)))*(pow(temp,2)))-
((5.481717*(pow(10,-2)))*(pow(relat_humid,2)))+
((1.22874)*(pow(10,-3))*(pow(temp,2))*(relat_humid))+
((8.5282)*(pow(10,-4))*(temp)*(pow(relat_humid,2)))-
(1.99*(pow(10,-6))*(pow(temp,2))*(pow(relat_humid,2)));
heat_index_y = heat_index + 15;
humi_index_y = humi_index + 9;
/* Print output values */
printf("\n\nRESULTS");
printf("\nTemperature (degrees F):");
printf("\nTemperature (degrees C):");
printf("\nRelative Humidity:");
printf("\n\nHeat index:");
printf("Humidex:");
printf("WARNING: IF STATEMENT REQUIRED");
printf("\n********************************************\n\n\n");
/* Exit the program */
return 0;
}
/*********************************************************************/
Was ist das Problem? – immibis
Wo ist 'temp' definiert? Was ist sein Typ? – user2357112
Bitte erklären Sie, welches Verhalten Sie beobachten und erklären Sie, wie es sich von dem unterscheidet, was Sie erwartet haben. –