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...
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...
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 mips assembly code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
Write a program and ask a user to enter a numeric value between 0 - 99....
Write a program and ask a user to enter a numeric value between 0 - 99. Your program will spell out the numbers into words. You must use at least three switch cases in addition to multiple if statements. Each missing switch statement will reduce your grade for this problem by 20%. Note: The total number of if statements and switch cases should not exceed 28. Additional if/case statement will further reduce your grade by 5%. in c++ please
Flowchart + Python. Ask the user for a value. Then, ask the user for the number...
Flowchart + Python. Ask the user for a value. Then, ask the user for the number of expressions of that value. Use While Loops to make a program. So then, it should be so that 5 expressions for the value 9 would be: 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 Flowcharts and Python Code. Not just Python code. I cannot read handwriting....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT