Hi i am learning C++
i typed the following programm
it is asking me to enter the age , when i enter age and hit eneter button it is generating the following message
test2.exe has generated errore and will be closed by windows you will need to resterat the programm
an error log is being created
i did't underatsnd whats wrong with the programm
i think it some thing relates to linking the programm
can any one help me in this matter

i am doing this in windows 2000 using dev C++ compiler

#include <iostream.h>
#include <stdlib.h>


     void main()
        {
        int age;
        cout<<"enter age\n";
              cin>>"age";
        if(age<=18)
        cout<<"child\n";
        cin.get();
        }

i i am learning C++
i typed the following programm
it is asking me to enter the age , when i enter age and hit eneter button it is generating the following message
test2.exe has generated errore and will be closed by windows you will need to resterat the programm
an error log is being created
i did't underatsnd whats wrong with the programm
i think it some thing relates to linking the programm
can any one help me in this matter
i am doing this in windows 2000 using dev C++ compiler

#include <iostream.h>
#include <stdlib.h>


     void main()
        {
        int age;
        cout<<"enter age\n";
              cin>>"age";
        if(age<=18)
        cout<<"child\n";
        cin.get();
        }

.

Tht should work.... although i would declare it has

int main()
{
int age = 0;

cout << "Please enter your age" << endl; //(endl creates new line)
cin >> age;

if ( age <=18)
    cout << "Child";
else
    cout << "Adult";

return 0;
}

it is compiling well ,
asking for age
when i enter age and press enter button
i am not seeing the result on the window , it is disapperaing
even if i use cin.get()
it is not displaying the result
is there any thing to do with linking out put file ????

that should work.... although i would declare it has

int main()
{
int age = 0;

cout << "Please enter your age" << endl; //(endl creates new line)
cin >> age;

if ( age <=18)
cout << "Child";
else
cout << "Adult";

return 0;
}

you could try the system pause? ...thats all i can think of for the moment but i'm sure the others on this forum wil think of something better to use

system("pause")

i think

add

std::string dummy;
cin << dummy;

your cin.get() was probably reading the enter you pressed...

when i use
system pause command
it is displaying the result on the output window
thanks

add

std::string dummy;
cin << dummy;

your cin.get() was probably reading the enter you pressed...

Another trick is to simply trap the enter key with another cin.get() like this:

#include <iostream>

using namespace std;

int main()
{
  int age;
  
  cout << "enter age\n";
  cin >> age;
  if (age <= 18)
    cout << "child\n";
    
  cin.get();  // trap enter
  cin.get();  // wait
  return 0;
}

Hello,

I believe that there is a flag on the icon from within Windoze that controls window behavior. Look for something along the lines of closing window when done executing. Look in the Program tag, and uncheck "Close on exit".

Christian

#include <iostream.h>
#include <stdlib.h>


void main()
{
int age;
cout<<"enter age\n";
cin>>"age";
if(age<=18)
cout<<"child\n";
cin.get();
}

just in case you missed it. age should NOT have "" around it as it is a variable that you are intending to store the age in. This would cause the error (cin acesses bad memory i think ;) ) Acidburn and vegaseat corrected it without realising! * claps * They are also correct about the get function. Your last cout put a '\n' character at the end so the next cin.get will read that '\n' and pass on. Another cin.get or system("PAUSE") or even a getchar() (needs #include <stdio>) gets the job done.

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.