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.
Level 7 - String operations
0/9 0 of 9 activities solved
Debit card
Not yet solved
Teacher code
Not yet solved
Caesar cipher
Not yet solved
Airline ticket
Not yet solved
Disemvowel
Not yet solved
Your move
Not yet solved
Tweet
Not yet solved
Valid address
Not yet solved
Palindrome
Not yet solved
Next series
Level 8 - Files and exceptions
Back to course
Level 7 - String operations
Next activity
Teacher code
Sign in to hand in your solution and get feedback.
// 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.");
}
}
Feedback