Question: I am working on a normal program,where i ask users for input of names .Two options are given ,add and print and if users enters

I am working on a normal program,where i ask users for input of names .Two options are given ,add and print and if users enters add,then user input is stored in the array and again two options are given.If user wants the added names,then choose 2 and the program stops.The program is working fine,but there is one problem.It doesn't like spaces between ,so i enter "John Smith "then it creates problems.I tried different things like changing data type and using getline function,but wasn't able to get the program working.

#include #include

using namespace std;

int main () {

string Names[5]; bool a = true; int count = 0; int input; cout << "Enter 1 for ADD and 2 for PRINT "; while(a){ cout << "Enter 1 or 2 " << endl; cin >> input; if (input == 1) { if (count > 4 ){ cout << "ALERT ! You are out of space "; a = false; } else{ cout << "Enter the Full Name: "; cin >> Names[count];

count++; a = true; } }

else if (input == 2) { for (int i = 0; i < count; i ++){ cout << Names[i] << " "; } a = false; } else { cout << "Wrong Input"; a = false; }

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!