Question

I need to be able to input first and last name. My code only outputs first...

I need to be able to input first and last name. My code only outputs first when you put 2 names. This is not my full code. Any type of help wou;d be great!

int main()
{
int main_choice;
int grade_choice;
int std_id;
int new_grade;
char g_name[100];
char s_name[100];

float a,b,c;
gradebook g;
do
{

cout <<endl;
cout<< " -=| MAIN MENU |=-" << endl;
cout<< "1. Add a student" << endl;
cout << "2. Remove a student" << endl;
cout << "3. Change a student’s grade" << endl;
cout << "4. Change group weights" << endl;
cout << "5. Change the gradebook name" << endl;
cout << "6. Display class averages" << endl;
cout << "7. Display full report " << endl;
cout << "0. QUIT" << endl;
cout<<"Enter an action: ";
cin>>main_choice;

switch(main_choice) // the switch statement instead of if else wayyyy easier.
{

case 1:
cout<<" -=| ADDING STUDENT |=-" << endl;
cout<<"Please enter the student’s name: ";
cin>>s_name;
if(g.add_std(s_name))
cout<<"\n"<<s_name<<" was successfully added to the gradebook!";

0 0
Add a comment Improve this question Transcribed image text
Answer #1

never take a sentence from the keyboard by using this code "cin>>s_name;" it will read the only first word, suppose if you give input "VISHAL SINGH DANKUNI" then it will read only "VISHAL" and ignore "SINGH DANKUNI".

so to solve this problem, always use this :

getline(cin,_name);

it will read full name;

PLEASE GIVE THUMBS UP, THANKS

Add a comment
Know the answer?
Add Answer to:
I need to be able to input first and last name. My code only outputs first...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • this code below is not the full code. I need help outputting both first name and...

    this code below is not the full code. I need help outputting both first name and last name. Can you please fix my code. I use getline but it says sometthing is wrong with my if statement our whatever cout<<" -=| ADDING STUDENT |=-" << endl; cout<<"Please enter the student’s name: "; cin>>s_name; if(g.add_std(s_name)) cout<<"\n"<<s_name<<" was successfully added to the gradebook!"; else cout<<"\nStudents cannot be added because the gradebook is full!"; break;

  • How could I separate the following code to where I have a gradebook.cpp and gradebook.h file?...

    How could I separate the following code to where I have a gradebook.cpp and gradebook.h file? #include <iostream> #include <stdio.h> #include <string> using namespace std; class Gradebook { public : int homework[5] = {-1, -1, -1, -1, -1}; int quiz[5] = {-1, -1, -1, -1, -1}; int exam[3] = {-1, -1, -1}; string name; int printMenu() { int selection; cout << "-=| MAIN MENU |=-" << endl; cout << "1. Add a student" << endl; cout << "2. Remove a...

  • This is for a C++ program: I'm almost done with this program, I just need to...

    This is for a C++ program: I'm almost done with this program, I just need to implement a bool function that will ask the user if they want to repeat the read_course function. I can't seem to get it right, the instructions suggest a do.. while loop in the main function. here is my code #include <iostream> #include <cstring> #include <cctype> using namespace std; const int SIZE = 100; void read_name(char first[], char last[]); void read_course(int & crn, char des[],...

  • Help with C++ reverse program with leading zeros. I need to put the line from the...

    Help with C++ reverse program with leading zeros. I need to put the line from the function that display the zeros in main not in the function. So how can I move the display with leading zeros in main. Thanks. Here is my code. #include <iostream> #include <cstdlib> #include <iostream> using std::cout; using std::cin; using std::endl; //function templates int reverseNum(int); int main() { //variables char buf[100]; int num; while (true) { //prompt user for input cout << "Enter the number...

  • I need help with this C++ problem so far my algorithm is looking like this. #include...

    I need help with this C++ problem so far my algorithm is looking like this. #include using namespace std; void input(char fullname[35], int weight, int distance); double totalcharges(); main() { char fullname[35]; int weight; int distance; for(int i = 1; i <= 3; i++) {   input(fullname, weight, distance); } } void input(char fullname[35], int weight, int distance) { char f[35]; //full name int w; // weight int d; // distance cout << "What is your full name? Please enter `...

  • I need help in my C++ code regarding outputting the enums in string chars. I created...

    I need help in my C++ code regarding outputting the enums in string chars. I created a switch statement for the enums in order to output words instead of their respective enumerated values, but an error came up regarding a "cout" operator on my "Type of Item" line in my ranged-based for loop near the bottom of the code. I tried casting "i.type" to both "i.GroceryItem::Section::type" and "i.Section::type", but neither worked. Simply put, if a user inputs 1 as their...

  • C++ programming I need at least three test cases for the program and at least one...

    C++ programming I need at least three test cases for the program and at least one test has to pass #include <iostream> #include <string> #include <cmath> #include <iomanip> using namespace std; void temperatureCoverter(float cel){ float f = ((cel*9.0)/5.0)+32; cout <<cel<<"C is equivalent to "<<round(f)<<"F"<<endl; } void distanceConverter(float km){ float miles = km * 0.6; cout<<km<<" km is equivalent to "<<fixed<<setprecision(2)<<miles<<" miles"<<endl; } void weightConverter(float kg){ float pounds=kg*2.2; cout<<kg<<" kg is equivalent to "<<fixed<<setprecision(1)<<pounds<<" pounds"<<endl; } int main() { string country;...

  • I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7:...

    I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account:      Customer name      Customer address      City      State      ZIP code      Telephone      Account balance      Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the...

  • I want c++ code for employee payslip calculation using switch statement convert this code to switch...

    I want c++ code for employee payslip calculation using switch statement convert this code to switch statement also, use for loop ___________________________________________________________________________ #include using namespace std; int main() {char empname[222]; float basicSalary, h_r_a, DearnessAllow, tax, netSalary; int e_id; cout<<"\nEmployee Name :"; cin>>empname; cout<<"\nEmployee Id :"; cin>>e_id; cout << "Enter Basic Salary : "; cin >> basicSalary; DearnessAllow = 0.30 * basicSalary; h_r_a= 800; tax = 0.10 * basicSalary; netSalary = basicSalary + DearnessAllow + h_r_a - tax; cout<<"\nEmployee Id              :...

  • What did I do wrong with this C++ code? Assume that we don't need to ask...

    What did I do wrong with this C++ code? Assume that we don't need to ask users for the number of students. #include <iostream> #include <iomanip> using namespace std; int main() { float *grades; // a pointer used to point to an array int size; int count = 0; // track the number of grade/student float grade; // the grade of a student float average, total; // average grade and total grades //**************start your code here************************ cout<<"How many student grades...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT