![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Dec 2007
Posts: 16
Rep Power: 0
![]() |
Computations: extra inputs?
My program:
#include <iostream>
using namespace std;
int main()
{
//I'm declaring some variables.
int number1, number2, product, sum;
cout << "Please enter an integar (whole number): \n";
cin >> number1;
cout << "Please enter a another integar: \n";
cin >> number2;
//Computing the numbers.
product = number1 * number2;
sum = number1 + number2;
//This will reveal the final computations.
cout << "The sum of " << number1 << " and " << number2 << " equals: " << sum << "\n";
cout << "The product of " << number1 << " and " << number2 << " equals: " << product << "\n";
cin >> sum >> product;
cin.ignore();
return 0;
}The problem with this code is that after the program finishes everything that it needs to, it won't terminate. Instead, it forces me to input two extras times. I suspect that it's probably because of the code cin >> sum >> product; Thanks in advance.
__________________
Aspiring Game Designer |
|
|
|
|
|
#2 | |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 742
Rep Power: 3
![]() |
Re: Computations: extra inputs?
Quote:
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
|
|
|
#3 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8
![]() |
Re: Computations: extra inputs?
The problem is, when/if I remove that code, the program won't execute. I'd recommend doing this instead though: cin.get(); return 0; |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Question on a Homework extra credit. | Direth | Visual Basic | 2 | Dec 5th, 2007 2:20 PM |
| linked list keep getting extra node | kruptof | C++ | 10 | Dec 22nd, 2006 10:44 PM |
| Error handling inputs | Konnor | Java | 4 | Mar 11th, 2006 10:43 PM |
| struct program skipping inputs | codylee270 | C | 7 | Dec 5th, 2005 7:02 AM |
| A standards question, optional inputs into Methods | Arla | C# | 4 | Apr 27th, 2005 10:38 PM |