0

Can someone please correct this code for me, so it can produce the correct output. The code is to display the name of the patient, the doctor that treated him/her, the room where he/she was treated.

#include <iostream> 
using namespace std;

int main()
{
    string bisi[3][4] = {{"      ", "DOCTOR 1", "DOCTOR 2", "DOCTOR 3"},
{"ROOM 1", "AFUAH", "ARABA", "JOHNSON"},
{"ROOM 2", "BENJAMIN", "KOROMA", "CHELSEA"}};

    for (int row=0; row<3; row++){
        for (int col=0; col<4; col++){
            cout<<bisi [row][col]<<" "; /*I get error on this line.The angle bracket "<<" Error Message: No operator matches this operand.*/
        }
        cout<<endl;
    }

    return 0;
}
4
  • 1
    Can you identify what each element of bisi is supposed to mean please (and what their relation ship should be). Perhaps show us the output you want to see. Commented Mar 30, 2016 at 10:12
  • 1
    I accept this as a beginner's test program. But note that idiomatic C++ would not model a patient / doctor / room relationship in a multidimensional (C...) array like this. You would have class Doctor, class Patient, ... Commented Mar 30, 2016 at 10:17
  • if you're using c++ take advantage of its functionality and library. use a vector. if not just use plain C. Commented Mar 30, 2016 at 10:45
  • I am still a beginner please, i just need this done for an assignment given to me by my lecturer. Thanks Commented Mar 30, 2016 at 11:21

3 Answers 3

3

You need to change:

cout << bisi[row] << bisi[col] << " ";

to:

 cout << bisi[row][col] << " ";

bisi is a 2d array, bisi[row] or bisi[col] will just print you an address

Sign up to request clarification or add additional context in comments.

3 Comments

i used cout << bisi[row][col] << " "; but i get this "<<" error @DimChtz
@Sir_Martins Can you update the question with the new code and the error you get?
I changed my data type from "string" to "int" the code worked without error.
1

From an object oriented view point, this is bad style. Wrap the information in a class. e.g.

struct Appointment
{
  std::string patient;
  std::string doctor;
  std::string room;
}

and store that information in some kind of collection:

std::vector<Appointment> appointments;
appointments.emplace_back({"henk", "doctor bob", "room 213"});
appointments.emplace_back({"jan", "doctor bert", "room 200"});

printing could then be done by:

for (const auto &appointment: appointments)
{
  std::cout << appointment.patient
            << appointment.doctor
            << appointment.room
            << std::endl;
}

Comments

0

I just added the preprocessor directive #include <"string"> without the quotes and it worked fine. Thank You guys for helping out.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.