![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#21 |
|
Programmer
Join Date: Oct 2005
Posts: 49
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#22 |
|
Programmer
Join Date: Oct 2005
Posts: 49
Rep Power: 0
![]() |
ok i fixed it by using
system("PAUSE") but is there a way for it to not exit right away without using that. |
|
|
|
|
|
#23 |
|
Expert Programmer
|
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.
|
|
|
|
|
|
#24 |
|
Programmer
Join Date: Oct 2005
Posts: 49
Rep Power: 0
![]() |
^^^^^^^^^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.
|
|
|
|
|
|
#25 |
|
Expert Programmer
|
swap cin.clear(); for cin.ignore();
__________________
Join us at #programmingforums @ irc.freenode.net! My software never has bugs. It just develops random features.
|
|
|
|
|
|
#26 | |
|
Programmer
Join Date: Oct 2005
Posts: 49
Rep Power: 0
![]() |
Quote:
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? |
|
|
|
|
|
|
#27 |
|
Professional Programmer
|
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 |
|
|
|
|
|
#28 |
|
Expert Programmer
|
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.
|
|
|
|
|
|
#29 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#30 |
|
Programmer
Join Date: Oct 2005
Posts: 49
Rep Power: 0
![]() |
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 programand 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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|