This is an example from an assignment I'm working on in which we need to validate that the user enters at least 1 Like for the temp.like[3] array and 1 Dislike for the temp.dislike[3] array.
I tried using a while statement that said " while (temp.like == "") " or " while (temp.like == null) " but had trouble with both.
Can anyone suggest a validation method to make sure the user has entered at least 1 like and 1 dislike?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LikesAndDislikes
{
class Program
{
const int MAX_LIKES = 3;
const int MAX_DISLIKES = 3;
struct clientType
{
public string[] likes;
public string[] dislikes;
}
static void Main(string[] args)
{
clientType temp = new clientType();
temp.likes = new string[MAX_LIKES];
temp.dislikes = new string[MAX_DISLIKES];
Console.WriteLine("\nEnter at least 1 like\n");
for (int i = 0; i < MAX_LIKES; i++)
{
Console.WriteLine("{0}{1}", "Enter like # ", (i + 1));
temp.likes[i] = Console.ReadLine().Trim();
}
Console.WriteLine("\nEnter at least 1 dislike\n");
for (int i = 0; i < MAX_DISLIKES; i++)
{
Console.WriteLine("{0}{1}", "Enter dislike # ", (i + 1));
temp.dislikes[i] = Console.ReadLine().Trim();
}
print(temp);
}
static void print(clientType temp)
{
for (int i = 0; i < MAX_LIKES; i++)
{
Console.WriteLine("\nLike {0,-2}{1}",(i + 1), temp.likes[i]);
}
for (int i = 0; i < MAX_DISLIKES; i++)
{
Console.WriteLine("\nDislike {0,-2}{1}", (i + 1), temp.dislikes[i]);
}
}
}
}