Warning! It seems that you are using Dodona within another webpage, so not everything may work properly. Let your teacher know so that he can solve the problem by adjusting a setting in the learning environment. In the meantime, you can click this link to open Dodona in a new window.
Warning! The page was not fully loaded, probably because of a network issue. It could be that not all functionalities work as expected. Please try reloading the page.
Debit card
Sign in to test your solution.
// Debit card program
using System;
class Submission
{
// -------------------------
// Subprograms
// -------------------------
static bool validate_number(string number_on_card)
{
bool valid = true;
int number_of_characters = number_on_card.Length;
if (number_of_characters == 16 || number_of_characters == 19)
{
foreach (char character in number_on_card)
{
if (!Char.IsDigit(character) && character != ' ')
{
valid = false;
}
}
}
else
{
valid = false;
}
return valid;
}
static void input_card_details()
{
bool valid_card = false;
string number_input = "";
while (!valid_card)
{
Console.WriteLine("Enter the 16 digit number:");
number_input = Console.ReadLine();
valid_card = validate_number(number_input);
}
}
// -------------------------
// Main program
// -------------------------
public static void Main(string[] args)
{
input_card_details();
Console.WriteLine("Card details valid.");
}
}