Question

In: Computer Science

In C# When the user enters an invalid value, ask the user to repeatedly enter the...

In C#

When the user enters an invalid value, ask the user to repeatedly enter the value until a valid value has been entered. Gender must be ‘M’ or ‘F’. Residency must be ‘I’ or ‘O’.

Existing Code:

using System;

public class Student

{

  public int credit;

  public String firstname, lastname, gender, residency, edate;

  public void input()

  {

    Console.WriteLine("\nWelcome to the Continental University Registration System!");

Console.WriteLine("\nEnter data about a student");

Console.Write("First Name: ");

firstname = Console.ReadLine();

Console.Write("Last Name: ");

lastname = Console.ReadLine();

Console.Write("Gender (M/F): ");

gender = Console.ReadLine();

Console.Write("Residency (I/O): ");

residency = Console.ReadLine();

Console.Write("Credits Taking: ");

    credit = Convert.ToInt32(Console.ReadLine());

Console.Write("Entrance Date: ");

edate = Console.ReadLine();

    

  }

}

Solutions

Expert Solution

Code:

using System;
public class Student
{
public int credit;
public String firstname, lastname, gender, residency, edate;
public void input()
{
Console.WriteLine("\nWelcome to the Continental University Registration System!");
Console.WriteLine("\nEnter data about a student");
Console.Write("First Name: ");
firstname = Console.ReadLine();
Console.Write("Last Name: ");
lastname = Console.ReadLine();
do
{
Console.Write("Gender (M/F): ");
gender = Console.ReadLine();
}while(!(String.Equals(gender, "M") || String.Equals(gender, "F")));
do
{
Console.Write("Residency (I/O): ");
residency = Console.ReadLine();
}while(!(String.Equals(residency, "I") || String.Equals(residency, "O")));

Console.Write("Credits Taking: ");
credit = Convert.ToInt32(Console.ReadLine());
Console.Write("Entrance Date: ");
edate = Console.ReadLine();
}
}

Screenshot:


Related Solutions

Write Java code that allows a user to repeatedly enter numbers. Each time the user enters...
Write Java code that allows a user to repeatedly enter numbers. Each time the user enters a number, the program should print out the average of the last 3 numbers (or all numbers if 3 or less have been entered). I would like a detailed explanation so that a beginner level Java programmer could understand.
Assume user will enter letters or numbers that are out of range. When user inputs invalid...
Assume user will enter letters or numbers that are out of range. When user inputs invalid values, show an alert message and ask user to enter a valid value again. Validate first and then proceed with the program. isNaN() method may be useful. Must validate user input. 1. Suggested Filename: fortune.html & fortune.js Write a program that simulates a fortune cookie. The program should display one of five unique fortunes, depending on user input. The user must enter a number...
User is asked to enter a series of numbers. That input will stop when user enters...
User is asked to enter a series of numbers. That input will stop when user enters -9999. Find a maximum number from that series and a minimum number from that series. Output the location of Maximum number and minimum number.  Write a C++ program that asks the user to repeatedly input positive numbers until   -1 is pressed. Your program should print the second largest number and the count of even and odd numbers.  Write a C++ program that asks...
Language C++ Ask the user to enter their weight (in pounds) and their height in inches....
Language C++ Ask the user to enter their weight (in pounds) and their height in inches. Calculate their Body Mass Index (BMI) and tell them whether they are underweight, overweight, or at optimal weight. BMI formula: weight * 703 / (height * height) Optimal weight is a BMI from 19 to 26. Lower is underweight, higher is overweight. Prompts: Enter your weight (in pounds): [possible user input: 144] Enter your height (in inches): [posible user input: 73] Possible Outputs: Your...
Code in Java Change the instructionLabel to ask the user to enter a numeric value into...
Code in Java Change the instructionLabel to ask the user to enter a numeric value into the textField and click the button to convert the entered value from kilometers to miles (1.609344 km = 1 mile). When the actionButton on the form is clicked, ActionWindow should take the value entered in the textField, convert it from kilometers to miles, and display the result in the resultField. import java.awt.Container; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class...
In.java Write a program that repeatedly asks the user to enter their password until they enter...
In.java Write a program that repeatedly asks the user to enter their password until they enter the correct one. However, after 5 failed attempts, the program "locks out" the user. We will show that with an error message. Assume the password is HOC2141 (case sensitive). Note that there is a special case that is not shown below. To identify it, think of all possible scenarios of input for this program. ----------- Sample run 1: Enter your password: Blake Wrong Enter...
Write in C# please! Ask the user to enter all of their exam grades. Once they...
Write in C# please! Ask the user to enter all of their exam grades. Once they are done, calculate the minimum score, the maximum score and the average score for all of their scores. Perform this using at least 2 Loops (can be the same type of loop) and not any built in functions.
Write a program using C language that -ask the user to enter their name or any...
Write a program using C language that -ask the user to enter their name or any other string (must be able to handle multiple word strings) - capture the epoch time in seconds and the corresponding nanoseconds - ask the user to type in again what they entered previously - capture the epoch time in seconds and the corresponding nanoseconds -perform the appropriate mathematical calculations to see how long it took in seconds and nanoseconds (should show to 9 decimal...
Using C++ Write a program to ask user to enter a password and validity the password....
Using C++ Write a program to ask user to enter a password and validity the password. The password should be 8 – 20 characters long (8 is included and 20 is included), it should contain at least one uppercase letter and one lower case letter. The password should contain at least one digit, and at least one symbol other than alphabets or numbers. Most importantly, the password may not contain any white space. Functions: You will need at least the...
Write a C++ program to ask the user to enter the shape type: square, sphere or...
Write a C++ program to ask the user to enter the shape type: square, sphere or circle and the appropriate dimensions of the shape.. The program should output the following information about the shape: a.for a square. it output the area and perimeter. b. for a sphere, it outputs the area. c. fir a circle, it outputs the volume. if the user input anything else, your program should output: "the program does not recognize this shape". Use const whenever it...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT