help me fix the following code pls

please help me fix this code,

//Hospital doctor information system
#include <iostream>
#include <string>

using namespace std;
int main ()
{
string welcome_to_Lanka_Hospital;
string medical_service;
string allergies;
string cardiology;
string neurology;
string help;

cout <<"welcome to lanka hospital:";
cout <<"please select medical service:";

cout<<"allergies";
cout<<"cardiology";
cout<<"neurology";
cin>>medical_service;

}
if (medical_service=allergies)

{

cout<<"doctor information:";
cout<<"allergies dr ahmed room a"<<endl;
}
else
{
cout<<"help 0115530000 :"<<help<<endl;
}
if (medical_service=cardiology)
{
cout<<"doctor information:";
cout<<"cardiology dr moosa room b"<<endl;
}
else
{
cout<<"help 0115530000 :"<<help<<endl;
}

if (medical_service=neurology)
{
cout<<"doctor information:";
cout<<"neurology dr aisha room c"<<endl;

else
{
cout<<"help 0115530000 :"<<help<<endl;
}



system("pause");
}

i want to make the program in a way that when the medical service wanted is inputted i want that fields doctor information to appear, fix or write me a code using the above information thank you
closed account (48T7M4Gy)
Which part do you want us to fix?
i want to make the program ...
fix or write me a code

So many choices:
* You want to make a program
OR
* You want to get a program
OR
* You want to learn to program

Consider the difference between "assignment operator" and "test for equality".
What is an "empty string"?
i want to make a program for my assignment about a hospital doctors information program.
error occurs at if (medical_service=allergies), medical_service below because of that error the program is not built and run
closed account (48T7M4Gy)
You need something like a switch to do what I think you are attempting.

I suggest you look at the tutorials and samples on this site.

http://www.cplusplus.com/doc/tutorial/control/ under the section called
"another selection statement: switch"
//Hospital doctor information system
#include <iostream>
#include <string>

using namespace std;
int main ()
{
string welcome_to_Lanka_Hospital;

string allergies;
string cardiology;
string neurology;
string help;
string medical_service;
string medical_service1;
string medical_service2;
string medical_service3;
string medical_service = medical_service1;
string medical_service = medical_service2;
string medical_service = medical_service3;


string medical_service1=allergies;
string medical_service2=cardiology;
string medical_service3=neurology;


cout <<"welcome to lanka hospital:";
cout <<"please select medical service:";

cout<<"allergies";
cout<<"cardiology";
cout<<"neurology";
cin>>medical_service;


if (medical_service=medical_service1)

{

cout<<"doctor information:";
cout<<"allergies dr ahmed room a"<<endl;
}
else
{
cout<<"help 0115530000 :"<<help<<endl;
}
if (medical_service=medical_service2)
{
cout<<"doctor information:";
cout<<"cardiology dr moosa room b"<<endl;
}
else
{
cout<<"help 0115530000 :"<<help<<endl;
}

if (medical_service=medical_service3)
{
cout<<"doctor information:";
cout<<"neurology dr aisha room c"<<endl;
}
else
{
cout<<"help 0115530000 :"<<help<<endl;
}



system("pause");
}

uograde but now medical_service appears to have error,
in here

if (medical_service=medical_service1)
First, u must use "==", instead of "=" in "if (medical_service=medical_service1)" ; The others are the same as this.
Second , u should learn the using method for the string class.
closed account (48T7M4Gy)
Try building on this.

I suggest you add more arrays to cope with contact numbers, doctor names etc as parallel arrays. Who knows you might get to a stage where a struct or class (even several) becomes part of your learning trajectory.

Good luck with it :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <string>

using namespace std;

int main ()
{
    int service_no = 0;
    string welcome  = "Welcome to Lanka hospital.\n Please select medical service: ";
    string service[] = { "Allergies","Cardiology","Neurology","Help" };
    int no_services = sizeof(service)/sizeof(string);
    
    cout << welcome << no_services << " services are available: ";
    while( cin >> service_no and (service_no < 0 or service_no >= no_services))
    {
        cout << "Error, try again.\n";
    }
    
    cout << "You have selected: " << service[service_no] << endl;
    
    
   /* EXCEPT FOR EXTRACTING SOME USEABLE DATA YOU CAN BIN THIS PART
    if (medical_service=medical_service1)
        
    {
        
        cout<<"doctor information:";
        cout<<"allergies dr ahmed room a"<<endl;
    }
    else
    {
        cout<<"help 0115530000 :"<<help<<endl;
    }
    if (medical_service=medical_service2)
    {
        cout<<"doctor information:";
        cout<<"cardiology dr moosa room b"<<endl;
    }
    else
    {
        cout<<"help 0115530000 :"<<help<<endl;
    }
    
    if (medical_service=medical_service3)
    {
        cout<<"doctor information:";
        cout<<"neurology dr aisha room c"<<endl;
    }
    else
    {
        cout<<"help 0115530000 :"<<help<<endl;
    }
    
    */
    return 0;
}
Last edited on
#include <iostream>
#include <string>

using namespace std;

int main ()
{
int no_services = 0;
string welcome = "Welcome to Lanka hospital.\n Please select medical service: ";
string service[] = { "Allergies","Cardiology","Neurology","Help" };
int no_services = sizeof(service)/sizeof(string);

cout << welcome << no_services << " services are available: ";

while( cin >> "no_services (no_services < 0 or no_services >= no_services")

{
cout << "Error, try again.\n";
}

cout << "You have selected: " << service[no_services] << endl;


/* EXCEPT FOR EXTRACTING SOME USEABLE DATA YOU CAN BIN THIS PART
if (medical_service=medical_service1)

{

cout<<"doctor information:";
cout<<"allergies dr ahmed room a"<<endl;
}
else
{
cout<<"help 0115530000 :"<<help<<endl;
}
if (medical_service=medical_service2)
{
cout<<"doctor information:";
cout<<"cardiology dr moosa room b"<<endl;
}
else
{
cout<<"help 0115530000 :"<<help<<endl;
}

if (medical_service=medical_service3)
{
cout<<"doctor information:";
cout<<"neurology dr aisha room c"<<endl;
}
else
{
cout<<"help 0115530000 :"<<help<<endl;
}

*/
return 0;
}

this still appears to have errors pls fix thank u
What errors?
closed account (48T7M4Gy)
this still appears to have errors pls fix thank u

OK rizan, I think we are all done here. I get the picture. Just green tick the thread. Best wishes :)
Topic archived. No new replies allowed.