Jan 24, 2017 at 5:31am UTC
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
Jan 24, 2017 at 6:31am UTC
Which part do you want us to fix?
Jan 24, 2017 at 8:01am UTC
i want to make a program for my assignment about a hospital doctors information program.
Jan 24, 2017 at 8:10am UTC
error occurs at if (medical_service=allergies), medical_service below because of that error the program is not built and run
Jan 24, 2017 at 9:28am UTC
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"
Jan 25, 2017 at 1:59am UTC
//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)
Jan 25, 2017 at 4:01am UTC
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.
Jan 25, 2017 at 4:10am UTC
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 Jan 25, 2017 at 4:14am UTC
Jan 29, 2017 at 7:47am UTC
#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