A very basic problem about input output

  • Thread starter Thread starter Shing
  • Start date Start date
  • Tags Tags
    Input Output
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
Shing
Messages
141
Reaction score
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;
}
 
Physics news on Phys.org