Add problem 4 solution

This commit is contained in:
Madeline Busig 2024-10-30 12:41:56 -07:00
parent 8aa0b52797
commit 26a4446341
3 changed files with 31 additions and 1 deletions

7
include/p4.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef P4_H
#define P4_H
int prompt_value(void);
#endif

View File

@ -3,6 +3,7 @@
#include "p1.h" #include "p1.h"
#include "p2.h" #include "p2.h"
#include "p3.h" #include "p3.h"
#include "p4.h"
#include "p5.h" #include "p5.h"
void print_int_arr(int* arr, int size) { void print_int_arr(int* arr, int size) {
@ -44,7 +45,12 @@ int main(void) {
double sum_of_file = sum_file("input_p3.dat"); double sum_of_file = sum_file("input_p3.dat");
printf("Sum of file: %.2lf\n", sum_of_file); printf("Sum of file: %.2lf\n", sum_of_file);
//
// Problem 4
printf("Problem 4:\n");
int p4_value = prompt_value();
printf("You entered: %d\n", p4_value);
// Problem 5 // Problem 5
printf("Problem 5:\n"); printf("Problem 5:\n");
int num_alphanum = count_alphanumeric("Hello World!!"); int num_alphanum = count_alphanumeric("Hello World!!");

17
src/p4.c Normal file
View File

@ -0,0 +1,17 @@
#include "p4.h"
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int prompt_value(void) {
int value = 0;
do {
printf("Please enter an integer between 1 and 100: ");
scanf("%d", &value);
} while (value < 1 || value > 100);
return value;
}