-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathProgram.cs
More file actions
145 lines (119 loc) · 4.59 KB
/
Program.cs
File metadata and controls
145 lines (119 loc) · 4.59 KB
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
using System;
using System.Collections.Generic;
namespace Checkpoint1
{
class Program
{
static void Main(string[] args)
{
//Lists how many divisible by 3 numbers there are between 1 and 100.
Console.WriteLine("There are {0} numbers between 1 and 100 that are evenly divisible by 3", divideByThree());
Console.WriteLine("----------------------------------------------------------------------");
//Enter a number, get the factorial of that number.
Console.WriteLine("Enter a number you want the factorial of:");
Console.WriteLine(factorial());
Console.WriteLine("------------------------------------------------------------------------");
int secretNum = numGen();
int chances = 4;
Console.WriteLine("GUESS THE NUMBER:");
//While you have chances left, you can keep on guessing the number.
while (chances > 0)
{
Console.WriteLine("THE SECRET NUMBER IS " + secretNum);
int guess = playerGuess();
if (guess == secretNum)
{
Console.WriteLine("Congrats, You Win!");
break;
}
else if (guess != secretNum)
{
chances--;
Console.WriteLine("Wrong, you have {0} chance(s) left.", chances);
}
if (chances == 0)
{
Console.WriteLine("You've run out of tries. Try again.");
break;
}
}
Console.WriteLine("----------------------------------------------------------------------------");
Console.WriteLine("Enter a number; enter 'ok' to add all previous numbers up! ");
Console.WriteLine("The numbers you entered = " +addNumbers());
Console.WriteLine("------------------------------------------------------------------------------");
Console.WriteLine("Enter a series of numbers separated by a comma:");
Console.WriteLine("The largest number you entered is: " + LargestNum());
}
//Divide By Three project (Number 1 on list):
public static int divideByThree()
{
int divisibleByThree = 0;
for (int i = 0; i <= 100; i++)
{
if (i % 3 == 0)
{
divisibleByThree++;
}
}
return divisibleByThree;
}
//Factorials project (Number 3 on list):
public static string factorial()
{
int num = Convert.ToInt32(Console.ReadLine());
int fact = num;
//int i, num and fact. Start i at 1 less than input and go down to 1 then multiply those numbers together to find fact.
for (int i = num - 1; i >= 1; i--)
{
fact = fact * i;
}
string equation = $"{num} != {fact}";
return equation;
}
//Guess the number project.
public static int numGen()
{
//Gets a random number
Random rnd = new Random();
int num = rnd.Next(1, 11);
return num;
}
public static int playerGuess()
{
//Takes guess from player.
int num1 = Convert.ToInt32(Console.ReadLine());
return num1;
}
public static int addNumbers()
{
string userInput = Console.ReadLine();
List<int> inputList = new List<int>();
int sum = 0;
if(userInput.ToLower() != "ok")
{
while (userInput.ToLower() != "ok")
{
inputList.Add(Convert.ToInt32(userInput));
sum += Convert.ToInt32(userInput);
Console.WriteLine("Enter a number; enter 'ok' to add all previous numbers up! ");
userInput = Console.ReadLine();
}
}
return sum;
}
public static int LargestNum()
{
string input = Console.ReadLine();
string[] numArray = input.Split(",");
int largestNum = Convert.ToInt32(numArray[0]);
for(int i = 0; i < numArray.Length; i++)
{
if(largestNum < Convert.ToInt32(numArray[i]))
{
largestNum = Convert.ToInt32(numArray[i]);
}
}
return largestNum;
}
}
}