| | |
help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2005
Posts: 7
Reputation:
Solved Threads: 0
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 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();
}
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
•
•
•
•
Originally Posted by gtsreddy
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();
}
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;
}
•
•
Join Date: Jan 2005
Posts: 7
Reputation:
Solved Threads: 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 ????
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 ????
•
•
•
•
Originally Posted by Acidburn
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;
}
add
your cin.get() was probably reading the enter you pressed...
C++ Syntax (Toggle Plain Text)
std::string dummy; cin << dummy;
your cin.get() was probably reading the enter you pressed...
•
•
Join Date: Jan 2005
Posts: 7
Reputation:
Solved Threads: 0
when i use
system pause command
it is displaying the result on the output window
thanks
system pause command
it is displaying the result on the output window
thanks
•
•
•
•
Originally Posted by jwenting
add
C++ Syntax (Toggle Plain Text)
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:
[php]
#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;
}
[/php]
[php]
#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;
}
[/php]
May 'the Google' be with you!
•
•
•
•
#include <iostream.h>
#include <stdlib.h>
void main()
{
int age;
cout<<"enter age\n";
cin>>"age";
if(age<=18)
cout<<"child\n";
cin.get();
}
) 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. http://sales.carina-e.com
no www
no nonsense
coming soon to a pc near you! :cool:
no www
no nonsense
coming soon to a pc near you! :cool:
![]() |
Other Threads in the C++ Forum
- Previous Thread: queue , memory, 32k please
- Next Thread: an "(" expected??
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






