[C#] Data Type and Sequence - IPO Charts E

Date:     Updated:

Categories:

Tags:

📋 This is my note-taking from what I learned in the class “Programming 1 - COMP 100-002”

Problem

Create a program that calculates and displays the average of three numbers. The user will enter the three numbers.
Sample calculation:

  1. Sum = first + second + third → 9 + 7 + 5 = 21
  2. Average = sum / 3 → 21 /3

3 Column IPO Chart

Input Processing Output
first, second, third sum average
  Algorithm  
  1. Enter first, second and third  
  2. Calculate sum = first + second + third  
  3. Calculate average = sum / 3  
  4. Display average  

Solution

2 Column IPO Chart:

IPO Chart → C# Statements

  • Input: first, second, third

    // Input
    int first;
    int second;
    int third;
    
    /* int is a keyword that is used to declare a variable which can store an integral type of value (signed integer) the range from -2,147,483,648 to 2,147,483,647. It is an alias of System. */
    
  • Processing: sum
    // Processing
    int sum;
    
  • Output: average
    // Output
    int average;
    
  • Algorithm

    • Prompt for first

      Console.Write("Enter the first number");
      
    • Accept first

      first = Convert.ToInt32(Console.ReadLine());
      
    • Prompt for second

      Console.Write("Enter the second number");
      
    • Accept second

      second = Convert.ToInt32(Console.ReadLine());
      
    • Prompt for third

      Console.Write("Enter the third number");
      
    • Accept third

      third = Convert.ToInt32(Console.ReadLine());
      
    • Calculate sum = first + second + third

      sum = first + second + third;
      
    • Calculate average = sum / 3

      average = sum / 3;
      
    • Display average

      ```csharp
      Console.Write(average);
      ```
      


Console.Write




Back to Top

See other articles in Category CS

Leave a comment