| | |
Problem with user input
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: May 2006
Posts: 10
Reputation:
Solved Threads: 0
First of all, hello everyone. My problem is this. In writing a program which accepts multiple user inputs of type int, during the first run through the program, after the first cout << statement prints, I have to press enter twice in order for the second cout statement to display. The first cin only stores the first digit of the input, which messes up the calculation. On all subsequent runs through the program, everything works fine. I've had this problem on a few programs now. When my professor compiles the programs himself, using Visual C++, everything works the way it's supposed to, but at home I use Dev C++. I've also built the program using Ultimate++ and I get the same problem. Is there something wrong with my computer setup??
edit * Thanks for pointing out my stupidity Narue, hope that's a little better
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { int num1 , num2 , sum , lowBound, upBound; char repeat = 'y'; while (repeat == 'y') { num1 = 0; num2 = 0; sum = 0; cout << "Enter the first number: "; cin >> num1; cout << "\nEnter the second number: "; cin >> num2; if (num1 >= num2) { upBound = num1; lowBound = num2; } else { upBound = num2; lowBound = num1; } for( int i = lowBound; i <= upBound; i++ ) { sum += i; } cout << "\nThe sum of all numbers, inclusive, between " << lowBound << " and " << upBound << " is " << sum << ". \n"; cout << "Would you like to play again?: "; cin >> repeat; } system("Pause"); return 0; }
edit * Thanks for pointing out my stupidity Narue, hope that's a little better

•
•
Join Date: May 2006
Posts: 10
Reputation:
Solved Threads: 0
Here's another example of the problem I'm having. When I run this program:
It compiles with no errors, when I run the program it takes
11 entries, then it seems to concatenate the first digit of
the first entry with the second entry, so for an entry list like
this :
The output will say that the largest number is 99. Needless
to say, this is very annoying and makes testing programs
much more of a hassle. If anyone has any idea why this is
happening, please let me know. I'm using dev-c++ 4.9.9.2
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { const int MAX_NUM_INTEGERS = 10; long int integers[10]; long int i = 0, maximumValue = 0; cout << "Please enter 10 integers : \n\n"; while ( i < MAX_NUM_INTEGERS) { cin >> integers[i]; i++; if (integers[i - 1] > maximumValue) { maximumValue = integers[i-1]; } } cout << "\nThe largest number you have entered is " << maximumValue << "\n\n"; system("pause"); return 0; }
11 entries, then it seems to concatenate the first digit of
the first entry with the second entry, so for an entry list like
this :
C++ Syntax (Toggle Plain Text)
9 9 8 45 51 75 21 0 15 74 16
to say, this is very annoying and makes testing programs
much more of a hassle. If anyone has any idea why this is
happening, please let me know. I'm using dev-c++ 4.9.9.2
I am using dev-c++ 4.9.9.1 and your last code works just fine (Windows XP). I think the version should not make any difference, that is only an update of the IDE. Are you using g++ as the compiler?
I added a few test lines to your code ...
I added a few test lines to your code ...
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cstdlib> using namespace std; int main() { const int MAX_NUM_INTEGERS = 10; long int integers[10]; long int i = 0, maximumValue = 0; int k; cout << "Please enter 10 integers : \n\n"; while ( i < MAX_NUM_INTEGERS) { cout << i << " "; // for testing cin >> integers[i]; i++; if (integers[i - 1] > maximumValue) { maximumValue = integers[i-1]; } } // test cout of the array for (k = 0; k < sizeof(integers)/sizeof(int); k++) cout << integers[k] << endl; cout << "\nThe largest number you have entered is " << maximumValue << "\n\n"; system("pause"); return 0; }
May 'the Google' be with you!
•
•
Join Date: May 2006
Posts: 10
Reputation:
Solved Threads: 0
In the compile log it shows "Executing g++.exe" Under the compiler options in Dev-C++ it shows "Default Compiler", and in the program tab it lists
gcc.exe
g++.exe
make.exe
gdb.exe
windres.exe
dllwrap.exe
gprof.exe
These files are all in the c:\Dev-C++\bin directory. I have the same problem when I compile with Ultimate++. I uninstalled, redownloaded, and reinstalled Dev, with mingw-3.4.2, but that didn't fix anything.
My programs work fine on my professor's computer, too.
Thanks for your help.
gcc.exe
g++.exe
make.exe
gdb.exe
windres.exe
dllwrap.exe
gprof.exe
These files are all in the c:\Dev-C++\bin directory. I have the same problem when I compile with Ultimate++. I uninstalled, redownloaded, and reinstalled Dev, with mingw-3.4.2, but that didn't fix anything.
My programs work fine on my professor's computer, too.
Thanks for your help.
•
•
Join Date: May 2006
Posts: 10
Reputation:
Solved Threads: 0
I have reinstalled Dev and uninstalled Visual C# Express, since I first noticed the problem around the time I installed VC#, but it hasn't changed anything. I've searched every C++ forum I could find and looked all over bloodshed.net for anything that might help, but I haven't had any luck. Please help me out if you have any ideas.
![]() |
Similar Threads
- user input into a string (C++)
- Tutorial: User Input: Strings and Numbers [C++] (C++)
- Tutorial: User Input: Strings and Numbers [C] (C)
- inline assembly getting user input.(djgpp) (Assembly)
- Type Conversion of User Input: (C++)
- Error Checking for user input (Java)
- error checking of user input (C++)
- Creating a GUI that accepts user input help (Java)
- Need Help With Error Checking User Input (C)
- filtering bad user input (Java)
Other Threads in the C++ Forum
- Previous Thread: Saving Entered Data
- Next Thread: Select a development environment
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count data database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph homeworkhelp homeworkhelper iamthwee ifstream input int integer lib linux list 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 temperature template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






