Question

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;

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

Hi , as you have not provided the full code , i am not aware with your if() condition. but what i am providing you is the complete working of getline() :

C++ code :

#include<iostream>
using namespace std;
int main()
{
   cout<<" -=| ADDING STUDENT |=-" << endl;
  
   string s_name;               // variable for taking input of student name
  
   cout<<"Please enter the student’s name: ";
  
   // As we know that student name might contain more than one words in it. So , we'll use getline() here
   getline(cin,s_name);           // getline() is used for taking input of string which contains more than one words
  
   cout<<"Student Name = "<<s_name<<"\n";

//   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;

}

Output :

Note : For printing the first name and last name of the student , please split the s_name at 'space' , then you could easily print first name and last name.

if you still face any issue or need any other clarifications , please comment. I will help you for the same.

Add a comment
Know the answer?
Add Answer to:
this code below is not the full code. I need help outputting both first name and...
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
  • 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;...

  • 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...

  • Fix my code, if I the song or the artist name is not on the vector,...

    Fix my code, if I the song or the artist name is not on the vector, I want to user re-enter the correct song or artist name in the list, so no bug found in the program #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; class musicList{ private: vector<string> songName; vector<string> artistName; public: void addSong(string sName, string aName){ songName.push_back(sName); artistName.push_back(aName); } void deleteSongName(string sName){ vector<string>::iterator result = find(songName.begin(), songName.end(), sName); if (result == songName.end()){ cout << "The...

  • 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...

  • I need help solving this assignment, you are given a full piece of code that does not run correctly. Some of the bugs ca...

    I need help solving this assignment, you are given a full piece of code that does not run correctly. Some of the bugs can be found at compile time, while others are found at run time. Access the UserMenu.cpp code file (in the zip file in Start Here) and use debugging practices and the debugger in Visual Studio to find each bug. Fix the bug and write a comment in the code giving a description of how you found the...

  • C++ getline errors I am getting getline is undefined error messages. I would like the variables...

    C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...

  • 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...

  • This question is about calculating and printing payslips. User inputs his name, number of worked hours...

    This question is about calculating and printing payslips. User inputs his name, number of worked hours and hourly rate. below is the source file for my program...It's supposed calculate salaries. Given that a work week has 40 hours and over time is 1.5xnormalRate for each our of overtime My output is not working. what is wrong with this code? // Calculate and print payslips #include <iostream> #include <iomanip> using namespace std; const float workingHours = 40.0; void getData( string &employeeP,...

  • fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string>...

    fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str;    while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title);    getline(inFile, books[size].Author); getline(inFile, books[size].publisher);          getline(inFile,...

  • below i added the code, but while running it, makefile.win error showing. how i fix this?...

    below i added the code, but while running it, makefile.win error showing. how i fix this? 1.)waitlist.h #include<iostream> using namespace std; class guest{    public:    string name;    guest*next;    guest*prev;    guest(string);    }; class waitList{    int numberOfGuests;    guest* first;    guest* last;    public:        waitList();        void addPerson(string);        void deletePerson(string);        guest* getFirst();        guest* getLast();    }; 2.)waitlist.cpp #include<iostream> #include"waitlist.h" using namespace std; guest::guest(string name){    this->name...

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