0

I NEED HELP!!

I'm writing a program where the user inputs the pH Level and it goes and tells if it is a certain solution. Some of them work some don't Can somebody tell me where in my code I am going wrong. I am not asking for the solution just guidance to what may wrong and how to fix it

///////////////////////////////////////////////////////////////////////////////
//
// Name: NAME-OF-FILE
// Author: YOUR-NAME-GOES-HERE
// Course: CMPSC 101/121
// Purpose: WHAT-DOES-THIS-PROGRAM-DO.
//
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// Header Files...
///////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>

///////////////////////////////////////////////////////////////////////////////
// Namespaces used....
///////////////////////////////////////////////////////////////////////////////
using namespace std;

///////////////////////////////////////////////////////////////////////////////
// Type Definitions...
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// Function prototypes...
///////////////////////////////////////////////////////////////////////////////
int inputphlevel();
// Inputs the users pH Level
int computephlevel(int PHLEVEL);
// Looks to see if the pH corresponds to any categories
///////////////////////////////////////////////////////////////////////////////
// Constants...
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
//
// FUNCTION NAME: main
// PARAMETERS: None
// RETURN TYPE: int
// PURPOSE: Entry point for the application.
//
///////////////////////////////////////////////////////////////////////////////

int main()
{
int phlevel = 0; //stores the pH Level

cout << "Please enter the pH Level: ";
// read in the value....
cin >> phlevel;

int PHLEVEL;
PHLEVEL = computephlevel (phlevel);

cout.setf(ios::fixed); // set up numeric output for real numbers...
cout.precision(4); // set up numeric output for 4 digits of precision....


return 0;
}

///////////////////////////////////////////////////////////////////////////////
//
// FUNCTION NAME: int computephlevel()
// PARAMETERS: PHLEVEL
// RETURN TYPE: int
// PURPOSE: Grabs the users input pH Levels
//
///////////////////////////////////////////////////////////////////////////////

int computephlevel(int PHLEVEL)
{
if (PHLEVEL == 0.0 && 3.0)
{
cout << "You're solution is Very Acidic" << endl;
}
else if (PHLEVEL == 3.0 && 7.0)
{
cout << "You're solution is Acidic" << endl;
}
else if (PHLEVEL == 7.0)
{
cout << "You're solution is Neutral" << endl;
}
else if (PHLEVEL == 7.0 && 12.0)
{
cout << "You're solution is Alkaline" << endl;
}
else if (PHLEVEL == 12.0 && 14.0);
{
cout << "You're solution is Very Alkaline" << endl;
}
return PHLEVEL; 
}

Edited by rbduck09: n/a

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Ancient Dragon
0

All the if statements starting on line 79 are wrong. Why? Because PHLEVEL is an integer, therefore by definition it does not have decimals. PHLEVEL is not a real number (float or double). Those lines are also badly formed -- they need to be like this: if( PHLEVEL >= 0 && PHLEVEL <= 3) lines 61 and 62 will do nothing because you never print the value of computephlevel().

Edited by Ancient Dragon: n/a

0

All the if statements starting on line 79 are wrong. Why? Because PHLEVEL is an integer, therefore by definition it does not have decimals. PHLEVEL is not a real number (float or double). Those lines are also badly formed -- they need to be like this: if( PHLEVEL >= 0 && PHLEVEL <= 3) lines 61 and 62 will do nothing because you never print the value of computephlevel().

Okay I got that part, but now when I enter 7.0 it gives back neutral. That's correct but when I enter 7.1 it gives back neutral but it is supposed to be alkaline.... I don't which binary operator to use

///////////////////////////////////////////////////////////////////////////////
//
// Name: NAME-OF-FILE
// Author: YOUR-NAME-GOES-HERE
// Course: CMPSC 101/121
// Purpose: WHAT-DOES-THIS-PROGRAM-DO.
//
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// Header Files...
///////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>

///////////////////////////////////////////////////////////////////////////////
// Namespaces used....
///////////////////////////////////////////////////////////////////////////////
using namespace std;

///////////////////////////////////////////////////////////////////////////////
// Type Definitions...
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// Function prototypes...
///////////////////////////////////////////////////////////////////////////////
int inputphlevel();
// Inputs the users pH Level
int computephlevel(int PHLEVEL);
// Looks to see if the pH corresponds to any categories
///////////////////////////////////////////////////////////////////////////////
// Constants...
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
//
// FUNCTION NAME: main
// PARAMETERS: None
// RETURN TYPE: int
// PURPOSE: Entry point for the application.
//
///////////////////////////////////////////////////////////////////////////////

int main()
{
	int phlevel;
cout << "Please enter a pH level in the range [0.0...14.0]: ";
// read in the value....
cin >> phlevel;


phlevel = computephlevel (phlevel);

cout.setf(ios::fixed); // set up numeric output for real numbers...
cout.precision(4); // set up numeric output for 4 digits of precision....


return 0;
}

///////////////////////////////////////////////////////////////////////////////
//
// FUNCTION NAME: int computephlevel()
// PARAMETERS: PHLEVEL
// RETURN TYPE: int
// PURPOSE: Grabs the users input pH Levels
//
///////////////////////////////////////////////////////////////////////////////

int computephlevel(int PHLEVEL)
{
	if ( (PHLEVEL > 0.0) && ( PHLEVEL < 3.0 ) )
	{
		cout << " You're pH solution of " << PHLEVEL << " is Very Acidic" << endl;
	}
	else if ( (PHLEVEL >= 3.0 ) && ( PHLEVEL < 7.0 ) )
	{
		cout << " You're pH solution of " << PHLEVEL << " is Acidic" << endl;
	}
	else if ( (PHLEVEL == 7.0 ))
	{
		cout << "You're pH solution of " << PHLEVEL << " is Neutral" << endl;
	}
	else if ( (PHLEVEL > 7.0 ) && ( PHLEVEL < 12.0 ) )
	{
		cout << "You're pH solution of " << PHLEVEL << " is Alkaline" << endl;
	}
	else if ( (PHLEVEL >= 12.0 ) && ( PHLEVEL < 14.0 ) )
	{
		cout << "You're pH solution of " << PHLEVEL << " is Very Alkaline" << endl;
	}


	return PHLEVEL;
}
0

its still an integer -- you can not enter decimals because cin will just ignore them. So 7.0 is the same as 7.1 as far as cin is concerned.

How to correct that problem? Change all ints to floats. Then the if statements starting on line 79 will not have to be changed because PHLEVEL will be a float.

Edited by Ancient Dragon: n/a

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.