Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 27th, 2005, 3:30 PM   #21
D-Ferg27
Programmer
 
D-Ferg27's Avatar
 
Join Date: Oct 2005
Posts: 49
Rep Power: 0 D-Ferg27 is on a distinguished road
ok so this is my code now.

#include <iostream>
using namespace std;
int main()

{
    int i ;
    cout << "please enter an integer value: " ;
    cin >> i;
    cout << " \n the value you entered is" << i;
    cout << "and its double is...\n ";
    cout << i * 2; 
    
    cin.get();
    return 1;
}

it compiles and runs now but now im back to square one. now when the user puts in a value it does nothing. And when i hit enter it just flashes somthing then exits.
D-Ferg27 is offline   Reply With Quote
Old Oct 27th, 2005, 3:44 PM   #22
D-Ferg27
Programmer
 
D-Ferg27's Avatar
 
Join Date: Oct 2005
Posts: 49
Rep Power: 0 D-Ferg27 is on a distinguished road
ok i fixed it by using

system("PAUSE")

but is there a way for it to not exit right away without using that.
D-Ferg27 is offline   Reply With Quote
Old Oct 27th, 2005, 3:48 PM   #23
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
return 1; means there was an error.
change it to return 0;


put that instead of system pause.
cin.clear();
cin.get();
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Oct 27th, 2005, 3:54 PM   #24
D-Ferg27
Programmer
 
D-Ferg27's Avatar
 
Join Date: Oct 2005
Posts: 49
Rep Power: 0 D-Ferg27 is on a distinguished road
Post

^^^^^^^^^that doesn't work. The program start fine but when the user puts in a value and presses inter the result result flashes but then exits. Thats why a put in the pause thing, but i know there has to be a way without it.
D-Ferg27 is offline   Reply With Quote
Old Oct 27th, 2005, 4:11 PM   #25
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
swap cin.clear(); for cin.ignore();
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Oct 27th, 2005, 4:14 PM   #26
D-Ferg27
Programmer
 
D-Ferg27's Avatar
 
Join Date: Oct 2005
Posts: 49
Rep Power: 0 D-Ferg27 is on a distinguished road
Quote:
Originally Posted by coldDeath
swap cin.clear(); for cin.ignore();
thank you!!! now my program looks a whooole lot cleaner. before when i had the system pause it showed press any key to continue and i my opinion it made the program look sloppy and poorly made.

Now i can resume with the crappy tutorial. Should i keep on going with the tutorial or just pick up from where i left of in another one?
D-Ferg27 is offline   Reply With Quote
Old Oct 27th, 2005, 4:19 PM   #27
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 4 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
You could try the getch() call, which is defined in <conio.h>, but I'm not sure if that will work in Dev-Cpp. It will work in TurboC++ V. 1 (yes I still use that sometimes)
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply
Prm753 is offline   Reply With Quote
Old Oct 27th, 2005, 4:28 PM   #28
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
This way means your code isn't bloated with another header file.
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Oct 27th, 2005, 6:07 PM   #29
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
cin.clear () repairs the broken stream. It does NOT remove any characters that were left in the stream, unconsumed. Add cin.sync () for that. You can use things like getch if you're satisfied with producing non-portable code when there's no need for it. Seems like a bad idea, though.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 27th, 2005, 6:47 PM   #30
D-Ferg27
Programmer
 
D-Ferg27's Avatar
 
Join Date: Oct 2005
Posts: 49
Rep Power: 0 D-Ferg27 is on a distinguished road
why is it that most tutorials don't put the right code in. Im using dev-C++ and practically all code that is written in a turorial doesn't work for me for instance this.

// Sample program
// IEA September 1995
// Reads values for the length and width of a rectangle
// and returns the perimeter and area of the rectangle.

#include <iostream.h>

void main()
{
  int length, width;
  int perimeter, area;              // declarations
  cout <<  "Length = ";             // prompt user
  cin >> length;                    // enter length
  cout << "Width = ";               // prompt user
  cin >> width;                     // input width
  perimeter = 2*(length+width);     // compute perimeter
  area = length*width;              // compute area
  cout << endl
       << "Perimeter is " << perimeter;
  cout << endl
       << "Area is " << area
       << endl;                    // output results
} // end of main program

and i got it from this part of a tutorial this site

im actually starting to think that devC++ is not a standard compiler and thats why most code that i get from tutorials dont work. Is this true. Is there a better compiler?

Last edited by D-Ferg27; Oct 27th, 2005 at 7:03 PM.
D-Ferg27 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:36 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC