first commit
This commit is contained in:
33
RecurringRainfall/C/CMakeLists.txt
Normal file
33
RecurringRainfall/C/CMakeLists.txt
Normal file
@@ -0,0 +1,33 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
# Modify only these if one source file!
|
||||
project(CRecurringRainfall)
|
||||
set(CURRENT_PROJECT_CODE_NAME recurringrainfall)
|
||||
set(FILE_EXT c)
|
||||
# End
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD_REQUIRED True)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
|
||||
# We want all the warnings and as errors enabled
|
||||
if (MSVC)
|
||||
# warning level 4 and all warnings as errors
|
||||
add_compile_options(/W4 /WX)
|
||||
else()
|
||||
# lots of warnings and all warnings as errors
|
||||
add_compile_options(-Wall -Wextra -pedantic -Werror)
|
||||
endif()
|
||||
|
||||
add_executable(${CMAKE_PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/${CURRENT_PROJECT_CODE_NAME}.${FILE_EXT})
|
||||
|
||||
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
|
||||
${EXTRA_INCLUDES}
|
||||
)
|
||||
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC
|
||||
${EXTRA_LIBS}
|
||||
)
|
||||
|
||||
|
||||
42
RecurringRainfall/C/recurringrainfall.c
Normal file
42
RecurringRainfall/C/recurringrainfall.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Unused variables
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
float currentAverage = 0;
|
||||
unsigned int currentEntryNumber = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int ret, entry;
|
||||
|
||||
printf("Enter rainfall int, 99999 to quit: ");
|
||||
ret = scanf("%d", &entry);
|
||||
|
||||
if (ret)
|
||||
{
|
||||
if (entry == 99999)
|
||||
{
|
||||
printf("User requested quit.\n");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentEntryNumber++;
|
||||
currentAverage = currentAverage + (1.0f/currentEntryNumber)*entry - (1.0f/currentEntryNumber)*currentAverage;
|
||||
|
||||
printf("New Average: %f\n", currentAverage);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Invalid input\n");
|
||||
while (getchar() != '\n'); // Clear input buffer before asking again
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user