Problems with the cstring/gets_s commands

hi i have recently started my HND at college and have begun to learn C++ programming iam currently trying to create a payroll program for my coursework but im having problems as when i run the program and go into the input employee details part of my program it seems to skip the firstname input of the program but when i later put it into an infinite loop it skipped it the first time and then on the next loop allowed input of firstname and worked exactly as intended but the first one always skips the firstname. the problem is in the void submenu1 the first gets_s doesnt allow input here is my program:

/*this at the moment is the basic setup with incorrect dialogue
and without sub-menus which i need to create*/
#include <iostream>
#include <cstring>
using namespace std;
void MainMenu();
void SubMenu1();
int main()
{
MainMenu();
return 0;
}
void MainMenu()
{
system ("CLS");
int num;
char CharY ='N';
cout << "Welcom select the sub-menu you would like to use:\n";
cout << "1: Employee details\n";
cout << "2: Payroll information\n";
cout << "3: Exit\n";
cin >> num;
// the value of num determines the case sequence executed
switch(num) {
case 1:
SubMenu1();
break;
case 2:
cout << "add 2nd opening menu\n";
break;
case 3:
while(CharY !='Y')
{
cout << "Are you sure that you want to exit? ";
cin >> CharY;
cout<< endl;
}
break;
default:
cout << "You must enter either 1, 2 or 3.\n";
}
}
void SubMenu1()
{
system ("CLS");
int numMenu1;
char FirstName[32]; // the [32] determines how many characters can be input
char SecondName[32];
char HouseNum[4];
char RoadName[30];
char City[30];
char PostCode[8];
cout << "Select what you would like to enter:\n";
cout << "1: Input Employee Details\n";
cout << "2: View Employee Details\n";
cout << "3: Exit back to main menu\n";
cin >> numMenu1;
switch(numMenu1) {
case 1:
cout << "\n" << "First Name: ";
gets_s(FirstName);
cout << "\n" << "Second Name: ";
gets_s(SecondName);
cout << "\n" << "House Number: ";
gets_s(HouseNum);
cout << "\n" << "Road Name: ";
gets_s(RoadName);
cout << "\n" "City: ";
gets_s(City);
cout << "\n" << "Postcode: ";
gets_s(PostCode);
cout << "\n" << FirstName << " " << SecondName << endl << HouseNum << endl << RoadName << endl << City << endl << PostCode << endl;
break;
case 2:
cout << "menu under construction";
break;
case 3:
MainMenu();
break;
default:
cout << "You must enter either 1, 2 or 3.\n";
}
}

Thank you in advance for all your replys/help :)
craig
Last edited on
Topic archived. No new replies allowed.