This is my assignment: Write a program to helps health care staff keep track of a patient's cholesterol level. It needs to have a main function that calls another function, and the function must be declared before the main function using a function prototype. A function must be called checkLDL, and should assign a value to the parameter.
These are the values:
<100 Optimal
<130 Near optimal
<160 Borderline high
<190 High
>=190 Very High

I am not understanding functions at all. I don't even understand what application they have. Can someone please help explain them to me, and help explain what to do/where I'm going wrong? I've started a program but it is a complete mess.

#include <iostream>
#include <string>
using namespace std;

void level (int);
int main()
{
void level (int);
return 0;
}
void level (int)
{
int checkLDL = 0;
int clevel;
string name;
char Optimal;
char Near Optimal;
char Borderline high;
char High;
char Very High;

cout <<"What is your cholesterol level? " <<endl;
cin>>checkLDL;
while (checkLDL !=0)
{
if (checkLDL<130)
clevel = Optimal;
if (checkLDL<130 && checkLDL<100)
clevel=Near Optimal;
if (checkLDL<159 && checkLDL<130)
clevel = Borderline high;
if (checkLDL>190 && checkLDL>159)
clevel = High;
else (checkLDL>190);
clevel = Very High;
}

cout <<"Your cholesterol number is : " << checkLDL <<endl;
cout <<"Your cholesterol level is : " << clevel <<endl;
}

Recommended Answers

All 3 Replies

About program formatting: Don't write a program that is straight down the left-hand side of the screen like you have posted. Indent the lines so that they are easier to read and understand.

About functions -- see How Stuff Works

This does what I want but it's not in a function. How would I go about putting it in a function?

#include <iostream>
using namespace std;

int main ()
   {
int score;

cout << "What is your cholesterol score? " ;
cin>> score;

cout << "Your cholesterol score is: " <<score <<endl;

   {
       if (score<100)
       cout << "Your score is optimal.   ";
       if (score<130 && score>99)
       cout << "Your score is not optimal.   ";
       if (score<160 && score>129)
       cout << "Your score is borderline  high.";
       if (score<190 && score>159)
       cout << "Your score is high.   ";
       if (score>189)
       cout << "Your score is very high.   ";
   }

return 0;
   }
#include <iostream>
using namespace std;

int calChol ()
   {
int score;

cout << "What is your cholesterol score? " ;
cin>> score;

cout << "Your cholesterol score is: " <<score <<endl;

       if (score<100)
       cout << "Your score is optimal.   ";
       if (score<130 && score>99)
       cout << "Your score is not optimal.   ";
       if (score<160 && score>129)
       cout << "Your score is borderline  high.";
       if (score<190 && score>159)
       cout << "Your score is high.   ";
       if (score>189)
       cout << "Your score is very high.   ";

return 0;
   }


int main()
{
    calChol();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.