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.
PYTHON Ask the user to enter the number of students in the class. Thereafter ask the...
PYTHON Ask the user to enter the number of students in the class. Thereafter ask the user to enter the student names and scores as shown. Output the name and score of the student with the 2nd lowest score. NOTE: You may assume all students have distinct scores between 0 and 100 inclusive and there are at least 2 students NOTE: You may only use what has been taught in class so far for this assignment. You are not allowed...
C++ Bubble Sort Write a program that ask user to enter 7 numbers and store that...
C++ Bubble Sort Write a program that ask user to enter 7 numbers and store that in array. Display that all numbers before and after performing Bubble sort. You must have to create new function with required parameter to perform Bubble sort. Sample Run :- Enter 1 number :- 1 Enter 2 number :- 5 Enter 3 number :- 7 Enter 4 number :- 45 Enter 5 number :- 90 Enter 6 number :- 6 Enter 7 number :- 55...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT