So guys, its a little hard to explain what I want so I'll try anyway. Basically this program is to calculate 3 hourly PSI value and show the hazard level of the PSI.
I am having trouble with the second part, the main problem is I want to use the PSI value that I got to check the Hazard level and that is the part of the code I just can't seem to get.
Obviously this is part of the code and not the full one
Forgive me for my ignorance but I am unfamiliar with std::string and when trying to use it, it has given me many errors. I was hoping you can elaborate more on how it can be used properly
Are you using a C++ compiler? Afterall, this is a C++ forum.
Your headers and use of printf and C-style string seem to imply you're using C, not C++. std::string is a C++ feature.
If you can only use C, the best way to do this is to pass a pointer to a string array:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <string.h> // C header
void chkPSI (int* psi, char * Hazard)
{ if (0 <= psi || psi <= 50) strcpy (Hazard, "Good");
elseif (51 <= psi || psi <= 100) strcpy (Hazard, "Moderate");
elseif (101 <= psi || psi <= 200) strcpy (Hazard, "Unhealthy");
elseif (201 <= psi || psi <= 300) strcpy (Hazard, "Very Unhealthy");
else strcpy (Hazard, "Hazardous");
}
// In selectionAN, Hazard must be big enough for the longest string
char Hazard[15];
...
chkPSI (PSI, Hazard); // Pass the string array as an argument
...
printf("%s", Hazard); // Note change to string format
Are you using a C++ compiler? Afterall, this is a C++ forum.
Well then that explains that, sigh, it seems that i have been using C all along.
I usually refer to this site for most problems I usually have and it normally works so that explains that. I apologies for any inconveniences caused and thank you for all the help you have provided, I finally can get it to work.