C编程代码不断崩溃

时间:2017-02-18 04:52:31

标签: c

我正在为我的C程序编写一个get输入函数。代码编译成功,但是当代码运行时,它会崩溃,错误" main.exe停止工作。"事先,代码可以工作,但它表示超出每个值的范围。代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#define MIN_T -58
#define MAX_T 41
#define MIN_WCA 2
#define MAX_WCA 50

double calculateWindChill(int temperature, int windSpeed);
double convertTemperature(double windChill_F);
void displayResults(int temperature, int windSpeed, double windChill_F, double windChill_C);
bool getInput(int *pTemperature, int *pWindSpeed);
void performCalculations(int temperature, int windSpeed, double *pWindChill_F, double *pWindChill_C);
bool withinRange(int value, int min, int max);


int main(){
    int temperature, windSpeed;
    double windChill_F, windChill_C;

  getInput(&temperature, &windSpeed);

    printf("\nPatrick Borgman");
    printf("\nProject 2");
    return 0;
} //main

bool getInput(int *pTemperature, int *pWindSpeed){
    *pTemperature = 0;
    *pWindSpeed = 0;
    bool valid = false;

    printf("Enter a value for outside temperature: ");
    if(scanf("%d", *pTemperature) == true){
        if(withinRange(*pTemperature, MIN_T, MAX_T) == true){
            printf("Enter a value for wind speed: ");
            if(scanf("%d", *pWindSpeed)){
                if(withinRange(*pWindSpeed, MIN_WCA, MAX_WCA)){
                    //printf("....");
                    valid = true;
                }
                else{
                    printf("Error");
                }
            }
        }
    }
    return valid;
}


bool withinRange(int value, int min, int max){
    bool inRange = true;

    if(value < min || value > max){
        printf("\nThe value is out of range.");
        inRange = false;
    }
    return inRange;
}

0 个答案:

没有答案