-2

hey im lost on why this loop doesnt work it all seems right but nothing inside the while works please help the rest of the code is in other files if you need them i can post them

#include <stdio.h>
#include "weatherstation.h"
int dunits = METRIC;

void main(void)
{
char test;
InitializeWeatherStation();
while(1);
{
    UpdateWeatherStation();
    printf("Enter m for Metric units, b for British units, or q to quit");
    scanf_s("%c",&test);
    if(test == 'm')
    {
        dunits = METRIC;
    }
    else if(test == 'b')
    {
        dunits = BRITISH;
    }
    else if(test == 'q')
    {
        return;
    }
    DisplayWeatherData(dunits);
}
}
Dorad
  • 3,413
  • 2
  • 44
  • 71

2 Answers2

2
while(1);
{
    something;
}

is exactly the same as:

while(1)
{
}
{
    something;
}

In other words, what you have there is an infinite loop followed by a scoped block of code (which will never be reached).

Get rid of the semicolon and it should fix that particular problem.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • Similar answer : http://stackoverflow.com/questions/37482904/why-didnt-the-compiler-warn-me-about-an-empty-if-statement – AlphaGoku Oct 18 '16 at 05:34
1

You must not end the while(1) with a semi-colon dude. Because that's a null statement you wrote in there.

Pragun
  • 1,123
  • 8
  • 20