Skip to content

Instantly share code, notes, and snippets.

@dschinkel
Last active June 4, 2020 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dschinkel/b6a319d730e4651f73d42079317ad33c to your computer and use it in GitHub Desktop.
Save dschinkel/b6a319d730e4651f73d42079317ad33c to your computer and use it in GitHub Desktop.
C Example
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define NUMBER_OF_DAYS 3
// Put your code below:
int main(void)
{
int k, highEntry, lowEntry;
printf("-- -= == IPC Temperature Analyzer == = --\n");
for (int i = 1; i < NUMBER_OF_DAYS; i++)
{
Array entries = promptForTemperature();
bool isValid = validateInput(entries[1], entries[0])
if(isValid) break;
main();
}
}
promptForTemparature(){
printf("Enter the high value for day %d: ", i);
scanf("%d", &highEntry);
printf("Enter the low value for day %d: ", i);
scanf("%d", &lowEntry);
return [highEntry, lowEntry]
}
validateInput(lowEntry, highEntry){
if (highEntry > 42 || lowEntry < -42);
{
printf("Incorrect values, temperatures must be in the range 41 to -41, high must be greater than low.\n");
--i;
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment