Skip to content

Instantly share code, notes, and snippets.

@DeclanGas
Created June 23, 2022 16:38
Show Gist options
  • Save DeclanGas/737c3ac01f9dd8231b56216ead21a3c1 to your computer and use it in GitHub Desktop.
Save DeclanGas/737c3ac01f9dd8231b56216ead21a3c1 to your computer and use it in GitHub Desktop.
#include <cs50.h>
#include <stdio.h>
int result;
int get_positive_int(string prompt)
{
do
{
result = get_int("%s", prompt);
}
while (result <= 0);
return result;
}
int main(void)
{
int n = get_positive_int("Enter a positive number: ");
// print the output from our function
printf("My positive int is %i.\n", n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment