no output

there is no output when i type age

#include<iostream>
using namespace std;
void main()
{
int a;
cout<<"What is ur age?"<<endl;
cin>>a;
if(a<=10)
{

cout<<"u r a kid dude!!!"<<endl;
}
if(a>10 && a<=20)
{
cout<<"Hi gorgeous"<<endl;
}
if(a>=20 && a<30)
{
cout<<"bachay sumbhal.......yahan kia kr raha hay"<<endl;
if(a>=30 && a<50)
{
cout<<"Get a Job!!!!!!!"<<endl;
}
if(a>=50 && a<70)
{
cout<<"Reading Newspaper is my passion!!!"<<endl;
}
if(a>=70 && a<=100)
{
cout<<"This is it Sir!!!!!!!"<<endl;
}
}
}
Compiled your Code and works fine for me but the three if-cases after line 23 will alway be false.
I guess thats your problem.

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
30
31
32
33
34
35
36
37
38
39
40
41
#include<iostream>

using namespace std;
void main()
{
        int a;
        cout<<"What is ur age?"<<endl;
        cin>>a;

        if(a<=10)
        {

        cout<<"u r a kid dude!!!"<<endl;
        }

        if(a>10 && a<=20)
        {
        cout<<"Hi gorgeous"<<endl;
        }

        if(a>=20 && a<30)
        {
                cout<<"bachay sumbhal.......yahan kia kr raha hay"<<endl;


                if(a>=30 && a<50)
                {
                cout<<"Get a Job!!!!!!!"<<endl;
                }

                if(a>=50 && a<70)
                {
                cout<<"Reading Newspaper is my passion!!!"<<endl;
                }

                if(a>=70 && a<=100)
                {
                cout<<"This is it Sir!!!!!!!"<<endl;
                }
        }
}


And please put your code in [code]*your code here*[/code] tags next time ;3.
Last edited on
Another view notes to your code:
void main() is only supported by some Microsoft compilers. Use int main() instead. Use else ifs rather than a lot of ands:
Fixed code
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
30
31
32
33
34
#include<iostream>

using namespace std;
int main()
{
   int a;
   cout<<"What is ur age?"<<endl;
   cin>>a;

   if (a<=10)
   {
      cout<<"u r a kid dude!!!"<<endl;
   }
   else if (a<=20)
   {
      cout<<"Hi gorgeous"<<endl;
   }
   else if (a<30)
   {
      cout<<"bachay sumbhal.......yahan kia kr raha hay"<<endl;
   }
   else if (a<50)
   {
      cout<<"Get a Job!!!!!!!"<<endl;
   }
   else if (a<70)
   {
      cout<<"Reading Newspaper is my passion!!!"<<endl;
   }
   else if (a<=100)
   {
      cout<<"This is it Sir!!!!!!!"<<endl;
   }
}


EDIT:
Another problem you might be describing is the fact that the console closes unexpectedly at the end. Just add some pausing code: http://www.cplusplus.com/forum/beginner/1988/
Last edited on
closed account (1wqDSL3A)
OK. Your 1st problem: There actually is some output in the console, you just can't see it - you haven't told the compiler to hold, and so it displays the console after you type something in and closes it immediately. In order to keep the result on the screen type in:

getch();

(remember to add #include <conio.h> in headers section);

The other problem you haven't spotted is that you mixed up your closing braces - here's how it should look like i hope you can spot the mistake:

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
30
31
32
33
34
35
36
37
38
39
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int a;
    cout<<"What is ur age?"<<endl;
    cin>>a;
        if(a<=10)
        {
            cout<<"u r a kid dude!!!"<<endl;
        }
        
        if(a>10 && a<=20)
        {
            cout<<"Hi gorgeous"<<endl;
        }
        
        if(a>=20 && a<30)
        {
            cout<<"bachay sumbhal.......yahan kia kr raha hay"<<endl;
        }   
            
        if(a>=30 && a<50)
        {
            cout<<"Get a Job!!!!!!!"<<endl;
        }
        
        if(a>=50 && a<70)
        {
            cout<<"Reading Newspaper is my passion!!!"<<endl;
        }
        
        if(a>=70 && a<=100)
        {
            cout<<"This is it Sir!!!!!!!"<<endl;
        }
    getch();
}


EDIT: whoops! too late :P
Last edited on
getch() is non-portable and completely out of the question.
closed account (D80DSL3A)
This code:
1
2
3
4
if(a>10 && a<=20)
        {
            cout<<"Hi gorgeous"<<endl;
        }

We're helping pedophiles now?

EDIT: I apologize for the above remark.
I have 2 young daughters, it was a stupid knee jerk reaction.
Last edited on
Takiro u r right.....the problem is with last three cases after line 23..... y is that??????
closed account (1wqDSL3A)
getch() is non-portable and completely out of the question.


Non-portable?? What is this? - a new generation super-extra multimedia player or a stupid console program? getch() is perfect for the job....
why use getch() when you can just use cin.get() ?
What is this? - a new generation super-extra multimedia player or a stupid console program?

No, a forum to learn people how to code. That includes doing it the RIGHT way from the beginning, not unlearning habits. Unportability (and therefor getch()) is one of these bad habits. Throwing away better solutions (using functionality that is already implemented because you included the iostream library) is another one.
I agree. cin.get() is a superior solution for this problem than getch(), and even stupid console programs will benefit. Please don't get on the defensive; we're only trying to help here, and suggesting getch() when one can use cin.get() is generally not seem as helpful around here, and for a good reason too. :(

-Albatross
closed account (1wqDSL3A)
Sorry I've never used cin.get() before, my bad :-)

Unportability is one of these bad habits.


Ummm... sorry!!! I shall throw all my DirectX knowledge away because OGL is portable!
:\
I'm assuming that was sarcasm; it's good to use DirectX, if that's the way to go for your solution. When we are discussing on the beginners sub-forum, we try to keep things as open as possible (just as in the General C++ sub-forum). If this thread was posted in the Windows programming sub-forum, getch() would be an option. Still, it's not negligible that cin.get() does the job good (and is already included into the code) and thus it's not good practice to include conio.h, too.
closed account (1wqDSL3A)
ok i've already stated my opinion stop looking for a fight.
I'm assuming that was sarcasm; it's good to use DirectX, if that's the way to go for your solution. When we are discussing on the beginners sub-forum, we try to keep things as open as possible (just as in the General C++ sub-forum). If this thread was posted in the Windows programming sub-forum, getch() would be an option. Still, it's not negligible that cin.get() does the job good (and is already included into the code) and thus it's not good practice to include conio.h, too.


+1

ok i've already stated my opinion stop looking for a fight.


-1

Why you assuming he's looking for a fight, please take your retarded comments elsewhere.
closed account (1wqDSL3A)
You are starting to write some nasty stuff, I suggest you shut up.
Topic archived. No new replies allowed.