help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2005
Posts: 7
Reputation: gtsreddy is an unknown quantity at this point 
Solved Threads: 0
gtsreddy gtsreddy is offline Offline
Newbie Poster

help

 
0
  #1
Jan 7th, 2005
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();
}
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: help

 
0
  #2
Jan 7th, 2005
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;
}
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 7
Reputation: gtsreddy is an unknown quantity at this point 
Solved Threads: 0
gtsreddy gtsreddy is offline Offline
Newbie Poster

Re: help

 
0
  #3
Jan 7th, 2005
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 ????






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;
}
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: help

 
0
  #4
Jan 7th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: help

 
0
  #5
Jan 7th, 2005
add
  1. std::string dummy;
  2. cin << dummy;

your cin.get() was probably reading the enter you pressed...
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 7
Reputation: gtsreddy is an unknown quantity at this point 
Solved Threads: 0
gtsreddy gtsreddy is offline Offline
Newbie Poster

Re: help

 
0
  #6
Jan 7th, 2005
when i use
system pause command
it is displaying the result on the output window
thanks

Originally Posted by jwenting
add
  1. std::string dummy;
  2. cin << dummy;

your cin.get() was probably reading the enter you pressed...
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,025
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 932
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: help

 
0
  #7
Jan 7th, 2005
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]
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 1,620
Reputation: kc0arf is a jewel in the rough kc0arf is a jewel in the rough kc0arf is a jewel in the rough 
Solved Threads: 51
Team Colleague
kc0arf kc0arf is offline Offline
Posting Virtuoso

Re: help

 
0
  #8
Jan 7th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 445
Reputation: 1o0oBhP is an unknown quantity at this point 
Solved Threads: 6
1o0oBhP's Avatar
1o0oBhP 1o0oBhP is offline Offline
Posting Pro in Training

Re: help

 
0
  #9
Jan 8th, 2005
#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.
http://sales.carina-e.com

no www
no nonsense

coming soon to a pc near you! :cool:
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC