-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
150 lines (103 loc) · 3.28 KB
/
Program.cs
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// See https://aka.ms/new-console-template for more information
Console.WriteLine("----------Qusetion 1 -----------");
Console.Write("input text: ");
string firstword = Console.ReadLine();
Console.WriteLine($"length of text 1 is : {firstword.Length}");
Console.Write("input second text: ");
string secondword = Console.ReadLine();
Console.WriteLine($"length of text 2 is: {secondword.Length}");
int bothwordlength = firstword.Length + secondword.Length;
Console.WriteLine($"sum of {firstword} and {secondword} is {bothwordlength}");
int finalresult = bothwordlength < 20 ? bothwordlength + 20 : bothwordlength * 3;
Console.WriteLine($"the final result is {finalresult}");
Console.WriteLine("---------Question 2 ----------");
decimal cp = 200.876M;
decimal sp =255.425M;
decimal profit = sp - cp;
Console.WriteLine($"the profit made is {Math.Round(profit ,2)}");
Console.WriteLine("---------Question 3-----------");
string word = Console.ReadLine();
int index = word.IndexOf(word[2]);
Console.WriteLine($"lenghth of {word} is {word.Length}");
int addition = index + word.Length;
Console.WriteLine($"sum is = {addition}");
int character= addition;
char A = (char)character;
Console.WriteLine($"character value is {A}");
Console.WriteLine("--------Question 4--------");
Console.Write("input a number:");
int num01 = Convert.ToInt32(Console.ReadLine());
Console.Write("input second number: ");
int num02 = Convert.ToInt32(Console.ReadLine());
int result = Math.Max(num01, num02);
Console.WriteLine($"the greater of the 2 number is {result}");
Console.WriteLine("---------Question 5-----------");
int sum = 0;
int i = 0;
while ( i <= 4)
{
Console.Write("Please enter number :");
string input = Console.ReadLine();
int x;
bool isInteger = int.TryParse(input , out x);
if (!isInteger)
{
i--;
Console.Write("Invalid input! ");
}
sum += x;
i++;
}
Console.WriteLine($"The sum of the numbers is :{sum}");
Console.WriteLine("--------------Question 6 ------------");
const int value= 5;
Console.Write("input a number: ");
int firstnum = Convert.ToInt32(Console.ReadLine());
Console.Write("input second number: ");
int secondnum = Convert.ToInt32(Console.ReadLine());
int correctanswer = (firstnum + secondnum) - value;
Console.Write($"input ur answer: ");
int useranswer = Convert.ToInt32(Console.ReadLine());
if ( correctanswer != useranswer)
{
Console.WriteLine($"incorrect answer, the correct answer is {A}");
}
else{
Console.WriteLine("correct answer");
}
Console.WriteLine("-------Question 7 -----------");
Console.Write("input a number between 0 and 9: ");
int num = Convert.ToInt32(Console.ReadLine());
switch (num)
{
case 0:
Console.WriteLine("zero");
break;
case 1:
Console.WriteLine("one");
break;
case 2:
Console.WriteLine("Two");
break;
case 3:
Console.WriteLine("3");
break;
case 4:
Console.WriteLine("four");
break;
case 5:
Console.WriteLine("five");
break;
case 6:
Console.WriteLine("six");
break;
case 7:
Console.WriteLine("seven");
break;
case 8:
Console.WriteLine("8");
break;
case 9:
Console.WriteLine("nine");
break;
}