Function Requirments

I am having a problem making the three values return a single true or false.
I made each value return true and false but the question below says i need to make everything false. I have what i have done so far below as well.


2. Write a function validtemperatures which will receive three integers as parameters. The function will determine whether or not the three temperatures are valid–each in the range -15 to 110. The function will print each invalid temperature together with a message explaining why it is invalid (print one message if it is too big, a different one if it is too small). If all three temperatures are valid, the function will return true (or 1) to the main program; if any temperature is invalid, the function will return false (or 0).
The function validtemperatures can do all the calculations itself, or it can call another function (isvalid) to do the work. The isvalid function would receive ONE temperature value and determine if it is valid, returning to validtemperatures the value true (or 1) if the temperature is valid, false (or 0) if the temperature is invalid.





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
int validtemperatures(int 1, int 2, int 3)
{
     int a,b,c;

     if(a<-15 || a>110)
          outfile<<"False";
    elseif(a>-15)
          outfile<<a<<" Number entered was too small";
    elseif(a>110)
         outfile<<a<<" Number entered was too big";


     if(b>-15 && b<110)
          outfile<<"True";
    elseif(b>-15)
          outfile<<b<<" Number entered was too small";
    elseif(b>110)
         outfile<<b<<" Number entered was too big";


    if(c>-15 && c<110)
          outfile<<"True";
    elseif(c>-15)
          outfile<<c<<" Number entered was too small";
    elseif(c>110)
         outfile<<c<<" Number entered was too big";

         return 1;
}
Numeric constants are NOT valid variable names, does this even compile? You never set your variables 'a', 'b' or 'c' to anything before using them, this should throw at least a warning on a modern IDE. The first part of the assignment wants a boolean data type and you wrote yours to return an integer... why?
i didnt completely learn functions
and the a b c integers were declared its just that i forgot to save the file when i made the changes.
And the boolean i thought was optional because of the second part??
And thanks for such a fast response
The variables you called '1', '2' and '3' are called arguments, these are all visible in the scope of the function so you don't need to copy them to local variables or anything but you do need to rename them in this case. I suggest deleting Line 3 and renaming them to 'a', 'b' and 'c'. The boolean thing might be optional, this depends on your instructor but why risk it on something so easy to fix?
so i should get rid of int and right boolean a,b,c; ?
Line 1 should be:
 
bool validtemperatures(int a, int b, int c)

Line 3 should be deleted.
ok thanks
and for the body for the three values
how would i make it that when one value is false the whole data set it false meaning all three values are false and returned to the main program with the printed message?
and when it is true i return that to the main program
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
bool validtemperatures(int a, int b, int c)
{

     if(a>-15 && a<110)
          outfile<<"True";
    elseif(a>-15)
          outfile<<a<<" Number entered was too small";
    elseif(a>110)
         outfile<<a<<" Number entered was too big";


     if(b>-15 && b<110)
          outfile<<"True";
    elseif(b>-15)
          outfile<<b<<" Number entered was too small";
    elseif(b>110)
         outfile<<b<<" Number entered was too big";


    if(c>-15 && c<110)
          outfile<<"True";
    elseif(c>-15)
          outfile<<c<<" Number entered was too small";
    elseif(c>110)
         outfile<<c<<" Number entered was too big";

         return 1;
}
There are a few problems with your if statements, take a look here for a reference: http://www.cplusplus.com/doc/tutorial/control/#if
Topic archived. No new replies allowed.