943,696 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 334
  • C++ RSS
Oct 24th, 2008
0

help please

Expand Post »
Im a beginner at c++ and this program seem to be easy. Im tying to get this program to multiply numbers as there put in by the user and display the answer, but if the user inputs to consecitive negative numbers the program has to stop. What concept can I use to make the program multiply and stop when using consecitve negative numbers. Oh and my break keeps being illegal.
Thank you
Im really confused!!
C++ Syntax (Toggle Plain Text)
  1. #include "stdafx.h"
  2. # include <iostream>
  3. using namespace std;
  4.  
  5. int _tmain(int argc, _TCHAR* argv[])
  6. {
  7. int product;
  8. int b;
  9. int i;
  10. i=0;
  11. float sum;
  12. sum=1;
  13. {
  14. while (b>=0)
  15. i++;
  16. //enter values
  17. cout<<"Enter a number\n";
  18. cin>> b ;
  19. cin>> product;
  20. sum=product*b;
  21. }
  22. cout<<"Nunbers multiplied together equals "<<sum<<endl;
  23. cin>>b;
  24. if(i<0){
  25. i++;
  26. cout<<"One negative number entered\n";
  27. if(i<0){
  28. break;
  29. }
  30. cout<<"Second negative number entered, program stop\n";
  31.  
  32.  
  33. }
  34. return 0;
  35. }
Last edited by Ancient Dragon; Oct 24th, 2008 at 12:57 am. Reason: add code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bone7_7 is offline Offline
4 posts
since Sep 2008
Oct 24th, 2008
0

Re: help please

lines 13 and 14 are in reverse order. The { goes after the while statement, not before.

line 28 -- break -- is wrong because it is not inside any loop where a break is valid.

Here is how the function should work
C++ Syntax (Toggle Plain Text)
  1. top of loop
  2. enter variable x1
  3. enter variable x2
  4. are x1 and x2 the same and negative
  5. yes, then exit the loop
  6. multiply x1 * x2
  7. end of loop
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How to increse the width of the console screen
Next Thread in C++ Forum Timeline: Problems passing multidimensional arrays





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC