help please

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 4
Reputation: bone7_7 is an unknown quantity at this point 
Solved Threads: 0
bone7_7 bone7_7 is offline Offline
Newbie Poster

help please

 
0
  #1
Oct 24th, 2008
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!!
  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,440
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1473
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: help please

 
0
  #2
Oct 24th, 2008
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
  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
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC