A very basic problem about input output

In summary, the conversation is about writing a code with nine functions that involve printing and prompting for different types of variables such as character, integer, float, and double. The main function includes a list and a diagram, and the program will only print the list and then return. There is no specific question asked in the conversation.
  • #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;
}
 
Physics news on Phys.org
  • #2
It seems to me that the program will only print the list and then return.

But what exactly was your question?
 

Related to A very basic problem about input output

1. What is input and output in computer science?

Input and output refer to the data that is entered into a computer system and the results that are produced from processing that data. Input can come from various sources such as a keyboard, mouse, or sensors, while output can be displayed on a screen, printed on paper, or sent to other devices.

2. Why is input and output important in computer science?

Input and output are essential components of computer science because they allow us to interact with and receive information from computers. Without input, computers would have no way of receiving instructions or data, and without output, we would not be able to see the results of our input.

3. What is the difference between input and output devices?

Input devices are used to enter data or instructions into a computer, while output devices display or transmit the results of processing that data. Examples of input devices include keyboards, mice, and scanners, while output devices include monitors, printers, and speakers.

4. Can you provide an example of a basic input output problem?

A basic input output problem could involve asking a user to enter their name and then displaying a personalized greeting using that input. For example, the program could ask for the user's name, and if the input is "John," the output could be "Hello, John!"

5. What are some common challenges in input output problems?

Some common challenges in input output problems include handling different types of input (such as numbers and text), dealing with errors or invalid input, and ensuring the output is accurate and formatted correctly. It is also essential to consider user experience and make the input and output process as user-friendly as possible.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
929
  • Engineering and Comp Sci Homework Help
Replies
19
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
4K
  • Programming and Computer Science
Replies
4
Views
766
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
Back
Top