Problems with updating information in project

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 :

  1. View their information
  2. Update their information
  3. 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()
{

}

OK, two things.

Firstly, you need to go and read the forum instructions so that you can go back and modify your original posts (not re-post them) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. If you do not post it as "code" it can as you now see, be quite garbled and is always more difficult to read due to the font.

It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And even that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only single blanks between complete functional blocks.


Now posting in a Arduino forum, we presume you intend to compile this for an Arduino or similar microprocessor.

As such, using any "String" objects will commonly cause the program to function for a little while and then annoyingly crash. We would presume you do not want your program to do that, so you need to re-design it using character arrays instead of "String"s.

In case you are curious as to why, this is due to the inability of the "String" (capital "S") class to implement "garbage collection".