Advertisement
MateusMelo500

productOfNnumbers

Oct 5th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2.                    
  3. public class Program
  4. {
  5.     public static void Main()
  6.     {
  7.         int product = 1;    //product must start at '1' because '1' is the neutral element in a product of 'n' numbers
  8.         string inputData;
  9.        
  10.         do{
  11.             inputData = Console.ReadLine(); //I read one number input as a string for each of the do..while passes
  12.            
  13.             if( inputData != "x" ){ //if input date is not the string "x", then...
  14.                
  15.                 //...we update the product variable with the product of itself and the current inputed number
  16.                 product = product * Convert.ToInt32(inputData);//I update the total product with the current number recieved from the user
  17.                
  18.             }          
  19.            
  20.         }while( inputData != "x" );//while the input data is diferent than "x"
  21.        
  22.         Console.WriteLine("Product is: " + product );//after calculating the product, we write the result in the output
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement