CAN SOMEBODY HELP WITH THISSS

Im using an online executor. compileonline.com to run my codes.

Here is the problem. i put #include<conio> it says error so i removed it. problem solved.. i think.
Then I cant seem to get it right on the height=hb-hg?
also error on the getch(); ..
can someboy help?
because after this code there is a continuation of the weight, status, age and interests. INT.

i also put

int hg,hb,wg,wb,sg,sb,ag,ab,ig,ib; //thats after the first bracket ({),[int hg(int heightgirl)]
do i put this code then add the int height, int weight etc?

Here is the question for this program.
1. create a program which asks for the corresponding input to produce certain outputs.
INPUT:
Height of girl, Height of Boy
condition:
height of boy should not be less than 2inches but not greater than 6inches of height of girl
OUTPUT:
"Somebody has to grow up"


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
#include <iostream>
using namespace std;

int main()
{   
    
    {
    
    int hb;
    cout<<"Height of boy (in inches):";
    cin>>hb;
    
    
    
    int hg;
    cout<<"Height of girl (in inches):";
    cin>>hg;
    
    
    height= (hb-hg);
        if (height=<2 || height=>6)
            cout<<"Somebody has to grow up."<<endl;
    }
     
     
return 0;
getch();
}
Last edited on
you should write "getch()" before "return 0"
and also you should add "conio.h" to your program.
Also according to microsoft getch() is deprecated and you should use _getch() http://msdn.microsoft.com/en-us/library/ms235446.aspx http://msdn.microsoft.com/en-us/library/078sfkak.aspx

Another thing to mention if you are using an online compiler it probably won't have conio.h as it is non-standard, there is also no need to use getch() to keep the console open if that is what you are trying to do? There are of course better ways to keep the console open though: http://www.cplusplus.com/forum/beginner/1988/

if (height=<2 || height=>6) those are not valid c++ operators. The correct operators are >= and <= just like how you would say it in English; greater than or equal and less than or equal. Would be odd to say "equal or greater than" or with less than. I am also confused on your logic. Why do they grow up when the height is less than or equal to 2? or are you trying to say if the height is between 2 and 6 [2,6] then display that? If so it would look like if(height >= 2 && height <= 6) as in the height is greater than or equal to 2 and the height is less than or equal to 6.

*edit just noticed that height is not declared. Change line 20 to int height = hb - hg;

Also the assignment
height of boy should not be less than 2inches but not greater than 6inches of height of girl
This is worded very weird. Sounds like they are saying the height of the boy has to be in the range of (2, 6] so your logic would be flawed if that is true. It would mean something like if(height > 2 && height <= 6)
Last edited on
If height of girl is lets say 170in
Then the height of boy should not be 2in less than 170in and not greater than 176in.
Thats why i use height=hb-hg and the hb<=2 || hb>=6 if either of that is true then itll show the cout>>"Somebody has to grow up"

Should i use && instead? And are my brackets before int correct because im really confused about using the extra brackets {}{}{}{}{}{}{}
The extra braces in your case don't really do anything. But if you only need something temporary and not for the entire function you would do that. Basically any variables on the stack inside those braces will be destroyed when it goes out of scope. So something like
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

int main()
{
    int a = 3; //created on stack in main

    {
        int b = 5; //created on stack in this code block
        a = b*b;
     } //b is removed from stack

    //a is still on the stack

    //std::cout << b << std::endl; -----error it no longer exists
    std::cout << a << std::endl;

    return 0;
}


By the way I think your math is a tad bit off. If he is 2 inches shorter than her then the difference would be -2 not 2. 168 - 170 = -2 to confirm. If he is taller it works fine though 172 - 170 = 2. Also is the message to appear when she is growing I was under the assumption when he was but it seems as if she is. So here is a hint:

 
if(height <= -2 || height >= 6)
It seems as they are exclusive in your case.
Topic archived. No new replies allowed.