"getting started" file not found.... can u reupload please?
Now thing is from that they I understood something like if one is over 18 he can be the supervisor for the other two so they can all enter. Didn`t understand why the need for the while since it`s the while lesson =))Quote:
A group of three people attempt to walk into a bar. They must show their ID which indicates their age before they enter. Your program will take the input of these three ages and tell them if they’re too young to enter (consider if a person is 18 or older they are allowed to enter).
static void Main(string[] args)
{
int j = 0;
while (j < 3)
{
int age = int.Parse(Console.ReadLine());
if (age >= 18)
{
Console.WriteLine("Enjoy your stay");
}
else
{
Console.WriteLine("Sorry kiddo. Too young.");
}
j++;
}
}
static void Main(string[] args)
{
int a1 = int.Parse(Console.ReadLine());
int a2 = int.Parse(Console.ReadLine());
int a3 = int.Parse(Console.ReadLine());
int i = 0;
while (i < 1)
{
if (a1 >= 18)
{
Console.WriteLine("You may enter . 1");
}
else if (a2 >= 18)
{
Console.WriteLine("You may enter . 2");
}
else if (a3 >= 18)
{
Console.WriteLine("You may enter . 3");
}
else
{
Console.WriteLine("Go home kids..");
}
i++;
}
Console.ReadKey();
}
Hmm.. well, you get the three input values without actually asking them, so they have to KNOW to enter a number three different times before seeing any output. Also, you don't need a while if you're going to only do something once, it's a waste of machine code :p Here's a C++ example (Could use while, but meh.)Quote:
ROFL!
I`m actually having some fun with the 'homework' Inf is giving in these tuts.
Check this one out lol:
Now thing is from that they I understood something like if one is over 18 he can be the supervisor for the other two so they can all enter. Didn`t understand why the need for the while since it`s the while lesson =))
This is inf's solution:
this was mine:Code:static void Main(string[] args) { int j = 0; while (j < 3) { int age = int.Parse(Console.ReadLine()); if (age >= 18) { Console.WriteLine("Enjoy your stay"); } else { Console.WriteLine("Sorry kiddo. Too young."); } j++; } }
Seriously, if you are new to c# and dunno where to start, check these lessons out. They are fun =)Code:static void Main(string[] args) { int a1 = int.Parse(Console.ReadLine()); int a2 = int.Parse(Console.ReadLine()); int a3 = int.Parse(Console.ReadLine()); int i = 0; while (i < 1) { if (a1 >= 18) { Console.WriteLine("You may enter . 1"); } else if (a2 >= 18) { Console.WriteLine("You may enter . 2"); } else if (a3 >= 18) { Console.WriteLine("You may enter . 3"); } else { Console.WriteLine("Go home kids.."); } i++; } Console.ReadKey(); }
#include <iostream>
#include <stdlib.h>
typedef unsigned char byte;
int main(int argc, char* argv[])
{
byte Age = 0;
std::string _age;
for (byte b = 0; b < 3; b++)
{
std::cout << (Age == 0 ? "Hey kid, how old are you?: " : "What about you, how old are you?: ");
std::cin >> _age;
Age = atoi(_age.c_str());
if (Age >= 18)
std::cout << "Okay kid, go ahead." << std::endl;
else
std::cout << "Sorry kid, go home." << std::endl;
}
return 0;
}
aye i know lol.. that is why i was wondering about why implementing while but it was the lesson about while so i just put one in =)Quote:
Hmm.. well, you get the three input values without actually asking them, so they have to KNOW to enter a number three different times before seeing any output. Also, you don't need a while if you're going to only do something once, it's a waste of machine code :p Here's a C++ example (Could use while, but meh.)
Code:#include <iostream> #include <stdlib.h> typedef unsigned char byte; int main(int argc, char* argv[]) { byte Age = 0; std::string _age; for (byte b = 0; b < 3; b++) { std::cout << (Age == 0 ? "Hey kid, how old are you?: " : "What about you, how old are you?: "); std::cin >> _age; Age = atoi(_age.c_str()); if (Age >= 18) std::cout << "Okay kid, go ahead." << std::endl; else std::cout << "Sorry kid, go home." << std::endl; } return 0; }
whie (a < 1)
{
a++
}
I guess it does prove a point, that while loops can be used the same way, I don't use them that often, though.Quote:
aye i know lol.. that is why i was wondering about why implementing while but it was the lesson about while so i just put one in =)
ffs =))
who the hell does that =)) that`s why i posted it, for the lols :))Code:whie (a < 1) { a++ }