-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOct4, Week5, Assignment No 1
84 lines (75 loc) · 2.09 KB
/
Oct4, Week5, Assignment No 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
string studentName = "Alim Momin";
string studentNumber = "C0744374";
int AssignmentNumber = 1;
*/
using System;
namespace Assignment
{
class Program
{
static void Main(string[] args)
{
Hello hello = new Hello();
hello.Launch();
Console.ReadLine();
}
}
class Hello
{
public string myName = "C#";
int num1, num2;
private void SayHello()
{
Console.WriteLine("Hello, my name is "+ myName);
}
public void Launch()
{
this.SayHello();
this.GetUserInput();
if (this.ValidateInput())
{
Console.WriteLine("The sum is "+this.CalculateNumber());
}
else
{
// this.GetUserInput();
while (!ValidateInput())
{
this.GetUserInput();
}
Console.WriteLine("The sum is "+this.CalculateNumber());
}
}
private int CalculateNumber()
{
int intermediateValue = num1;
int sum = 0;
while(intermediateValue > num2)
{
sum += intermediateValue;
intermediateValue -= 3;
}
return sum;
}
private void GetUserInput()
{
//ask for 2 numbers and tell them first should be greater than second
Console.WriteLine("Give me 2 numbers: The first should be bigger than second");
Console.WriteLine("Enter the first Number: ");
num1 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the second Number: ");
num2 = int.Parse(Console.ReadLine());
//show the entered values
Console.WriteLine("Your first number is {0} and second number is {1}", num1, num2);
}
private bool ValidateInput()
{
if(num1 > num2)
{
return true;
}else
return false;
}
}
}