I made a simple program where a user can pick from the menu. My problem is where do i put this code properly inside the fuction of funcFloat and funcInteger
if (myFloat < 0) // this will output if the user entered a negative value {
printf ("You entered a negative value.\n\n");
}
else // this will output if the user entered a positive value
{
printf ("You entered a positive value.\n\n");
}
Here is the whole code i wrote:
#include "stdafx.h"
#include <stdio.h>
void load_menu(void);
void funcChar(void);
//void funcString(void);
void funcFloat(void);
void funcInteger(void);
//void funcDisplay(void);
int main(int argc, char** argv)
{
load_menu();
return 0;
}
void load_menu(void)
{
int choice;
do
{
printf("\n\n**** MAIN MENU ****\n\n");
printf("1. Enter a char\n");
// printf("2. Enter a string\n");
printf("2. Enter a float\n");
printf("3. Enter an integer\n");
// printf("5. Display the square of numbers from 1-100\n");
printf("4. Quit the Program\n\n");
printf("Enter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: funcChar();
break;
// case 2: funcString();
// break;
case 2: funcFloat();
break;
case 3: funcInteger();
break;
// case 5: funcDisplay();
// break;
case 4: printf("Quitting program!\n\n");
break;
default: printf("Invalid choice! Choose Again.\n");
break;
}
} while (choice != 4);
}
void funcChar(void)
{
char myChar;
int ch;
printf("\nEnter a letter: ");
scanf("%c",&myChar);
/* Flushes input buffer from the newline from scanf() */
while ( (ch = getchar()) != '\n' && ch != EOF) ;
printf("\nPress ENTER to return to MAIN MENU.");
while ( (ch = getchar()) != '\n' && ch != EOF);
return;
}
void funcFloat(void)
{
float myFloat;
int ch;
printf("\nEnter a decimal number: ");
scanf("%f",&myFloat);
/* Flushes input buffer */
while ((ch = getchar()) != '\n' && ch != EOF) ;
printf("\nPress ENTER to return to MAIN MENU.");
while ((ch = getchar()) != '\n' && ch != EOF);
return;
}
void funcInteger(void)
{
int myInt;
int ch;
printf("\nEnter a number: ");
scanf("%i",&myInt);
/* Flushes input buffer */
while ((ch = getchar()) != '\n' && ch != EOF) ;
printf("\nPress ENTER to return to MAIN MENU.");
while ((ch = getchar()) != '\n' && ch != EOF);
return;
}