Hello there,
I'm very new to C++ programming and I have a bit of a problem with a project I'm currently doing so just wondering could any of you help me because I have been searching for hours and I'm not sure how to do it correctly so first thing I'm doing a project which allows the user to user to enter their first name, last name, student id and age and store all their information in an array.
Next, it will show the user the main menu and ask the user if they would like to :
- View their information
- Update their information
- Exit
If the user selects “1”, it will call a function named “details” and display their details.
If the user selects “2”, then it will call a function named “update” and ask the user which
part of their information to update (name, id or age) and update their details stored in the array. I'm currently having trouble how to update this information so as I'm not entirely sure do I create a new function or is it possible do perform it without one.
Here's my code as I have the first chunk of it correctly but not sure how to update the information once the number "2" is pressed.
const int SIZE = 4;
void setup()
{
String first_name = "";
String last_name = "";
String student_id = "";
String age = "";
String myString = "";
Serial.begin(9600);
Serial.println("Enter your personal details here");
delay (2000);
String details;
Serial.println("Enter your first name: ");
while (first_name == "")
{
first_name = Serial.readString();
}
details[0] = first_name;
Serial.println(details[0]);
Serial.println("Enter your last name");
while (last_name == "")
{
last_name = Serial.readString();
}
details[1] = last_name;
Serial.println(details[1]);
Serial.println("Enter your student ID");
while (student_id == "")
{
student_id = Serial.readString();
}
details[2] = student_id;
Serial.println(details[2]);
Serial.println("Enter your age");
while (age == "")
{
age = Serial.readString();
}
details[3] = age;
Serial.println(details[3]);
delay(2000);
Serial.println("1) View your information ");
delay (1000);
Serial.println("2) Update your information ");
delay (1000);
Serial.println("3) Exit ");
delay (1000);
String num = "";
while (myString == "")
{
myString = Serial.readString();
}
int info = myString.toInt();
switch (info)
{
case 1: Serial.println("You have selected view your information");
Serial.println("Your first name is " + details[0]);
Serial.println("Your last name is " + details[1]);
Serial.println("Your student ID is " + details[2]);
Serial.println("Your age is " + details[3]);
break;
case 2:
Serial.println("Update your first name ");
Serial.println("Update your second name ");
Serial.println("Update your student ID ");
Serial.println("Update your age");
break;
case 3: Serial.println("You selected exit");
break;
}
}
void loop()
{
}