/*---------------------------------------------------------------------------
[Function main]
The purpose of this function is that
1.Ask the user for numbers and call the function int_in to see if they are
valid.
2.caluculate to see if this program is working (product and difference)
---------------------------------------------------------------------------*/
void main(void){
static int vel, time, v1, v2, dist, diff; //variables
vel = int_in("Enter Velocity :");
time = int_in("Enter Time:");
dist = vel * time;
printf("\fVt = %d",dist); //the result of the product
/*--------------------------------------------------------------------------
[Function int_in]
The purpose of this function is to determine if the numbers the user
entered are valid. If they are not valid, messages will appear on the
LCD.
---------------------------------------------------------------------------*/
int int_in(char *prompt){
int len; //length of number
int num; //binary number after the string
char line[20]; //array
printf("\f%s",prompt);
gets(line);
len = strlen(line);
sscanf(line,"%ld",&num); //convert a string to a number
for( ; ;){ //loop structure for if...else
if(gets(line) == NULL){
printf("\nToo Few Digits. Try Again.");
}
else if( len > 6){
printf("\nToo Many Digits. Try Again.");
}
/* includes */
#include "stdio.h"
#include "string.h"
/*prototype*/
int int_in(char *prompt );
/*---------------------------------------------------------------------------
[Function main]
The purpose of this function is that
1.Ask the user for numbers and call the function int_in to see if they are
valid.
2.caluculate to see if this program is working (product and difference)
---------------------------------------------------------------------------*/
void main(void){
static int vel, time, v1, v2, dist, diff; //variables
vel = int_in("Enter Velocity :");
time = int_in("Enter Time:");
dist = vel * time;
printf("\fVt = %d",dist); //the result of the product
/*--------------------------------------------------------------------------
[Function int_in]
The purpose of this function is to determin if the numbers the user
entered are valid. If they are not valid, messages will appear on the
LCD.
---------------------------------------------------------------------------*/
int int_in(char *prompt){
int len; //length of number
int num; //binary number after the string
char line[100]; //array
printf("\f%s",prompt);
gets(line);
len = strlen(line);
for( ; ; ){ //loop structure if...else
if(gets(line) == NULL){
printf("\f\nToo Few Digits. Try Again.");
}
else if( len > 6){
printf("\f\nToo Many Digits. Try Again.\v%s",prompt);
}