- #1
Shing
- 144
- 1
Homework Statement
Write a code with the following functions:
Function 1: print a list of 4 different type variables input and output:
character, integer, float, and double.
Function 2: prompt and return an input character.
Function 3: print out a given character.
Function 4: prompt and return an input integer number.
Function 5: print out a given integer number.
Function 6: prompt and return an input float number.
Function 7: print out a given float number.
Function 8: prompt and return an input double number.
Function 9: print out a given double number.
The Attempt at a Solution
# include <stdio.h>
void do_list(void)
int main ()
{ printf(" Choose to input a number among the following types:\n");
printf(" 1. a character\n");
printf(" 2. an integer\n");
printf(" 3. a float\n");
printf(" 4. a double\n");
return;
}
//====diagram ========
{ char achar;
int aint;
float afloat;
double adouble;
do_list();
printf("Input your chioce");
scanf("%d", &choice);
if(choice == 1) {
achar = input_char();
print_char(achar);
}
else if(choice == 2) {
ainteger = input_integer();
print_integer(ainteger);
}
else if(choice == 3) {
afloat = input_float();
print_float(afloat);
}
else(choice == 4) {
adouble = input_double();
print_double(adouble);
}
}
return 0;
//====main function I========
char input_char(void)
{
char achar;
printf("Type your character:");
fflush(stdin); //clean the input uffer area.
scanf("%c",&a);
return achar;
}
void print_char(char a)
{
printf(Your input is "%c\n",a);
return;
}
//====main function II========
int input_int(void)
{
int aint;
printf("Type your character:");
fflush(stdin); //clean the input uffer area.
scanf("%c",&b);
return aint;
}
void print_int(int b)
{
printf(Your input is "%c\n",b);
return;
}
//====main function II===========
float input_float(void)
{
float afloat;
printf("Type your character:");
fflush(stdin); //clean the input uffer area.
scanf("%f"",&c);
return afloat;
}
void print_float(float c)
{
printf(Your input is "%c\n",c);
return;
}
//=====main function III==========
double input_float(void)
{
double adouble;
printf("Type your character:");
fflush(stdin);
scanf("%c",&d);
return adouble;
}
void print_double(double d)
{
printf(Your input is "%c\n",d);
return;
}