Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. Exercise #1: Design and implement a program (name it PrintSum) that prompts the user for an integer values between 1 and 100. The program then uses a while loop to determine and print out the sum of all values between 1 and the entered value. The program rejects invalid input values with proper message such “Invalid Input. Try again.” Document your code and properly label the input prompt and the outputs as shown below.
  2.  
  3. Sample run 1:
  4.  
  5. You entered: 10
  6. Sum of values: 55
  7.  
  8. Sample run 2:
  9.  
  10. You entered: 120
  11. Invalid input. Try again.
  12.  
  13. Sample run 3:
  14.  
  15. You entered: 20
  16. Sum of values: 210
  17.  
  18.  
  19. --------------------------
  20.  
  21. namespace assignment_4_1_cameron_mcelwaney
  22. {
  23. class Program
  24. {
  25. static void Main(string[] args)
  26. {
  27. Console.WriteLine("Enter in a number between 1-100.");
  28. int cMax = Convert.ToInt32(Console.ReadLine());
  29. int x = 1;
  30. while (x < cMax)
  31. {
  32. x +=1;
  33. }
  34.  
  35. Console.WriteLine(x);
  36. Console.Read();
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement