Advertisement
AvengersAssemble

TwoNumbersDigitSums

Sep 14th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace TwoNumbersDigitSums
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int num1Total = 0, num2Total = 0, num1=0, num2=0;
  14.             bool wrongInput = true, num1NotOver = true, num2NotOver = true;
  15.             while (wrongInput)
  16.             {
  17.                 num1 = int.Parse(Console.ReadLine());
  18.                 num2 = int.Parse(Console.ReadLine());
  19.                 if (num2 > num1)
  20.                     wrongInput = false;
  21.                 else
  22.                     Console.WriteLine("ERROR! Second number must be bigger than first!");
  23.  
  24.             }
  25.             int num1ForCalcs = num1;
  26.             int num2ForCalcs = num2;
  27.             while (num1NotOver)
  28.             {
  29.                 num1Total += num1ForCalcs % 10;
  30.                 num1ForCalcs /= 10;
  31.                 if (num1ForCalcs == 0)
  32.                     num1NotOver=false;
  33.             }
  34.             while (num2NotOver)
  35.             {
  36.                 num2Total += num2ForCalcs % 10;
  37.                 num2ForCalcs /= 10;
  38.                 if (num2ForCalcs == 0)
  39.                     num2NotOver = false;
  40.             }
  41.             Console.WriteLine("First number digits sum: {0}. Second number digits sum: {1}", num1Total, num2Total);
  42.             if (num1Total > num2Total)
  43.                 Console.WriteLine(num1 +"'s digits sum is greater.");
  44.             else if (num1Total < num2Total)
  45.                 Console.WriteLine(num2 +"'s digits sum is greater.");
  46.             else
  47.                 Console.WriteLine("Numbers' digits' sum is equal!");
  48.             Console.ReadLine();
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement