| | |
help please
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 4
Reputation:
Solved Threads: 0
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!!
Thank you
Im really confused!!
C++ Syntax (Toggle Plain Text)
#include "stdafx.h" # include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int product; int b; int i; i=0; float sum; sum=1; { while (b>=0) i++; //enter values cout<<"Enter a number\n"; cin>> b ; cin>> product; sum=product*b; } cout<<"Nunbers multiplied together equals "<<sum<<endl; cin>>b; if(i<0){ i++; cout<<"One negative number entered\n"; if(i<0){ break; } cout<<"Second negative number entered, program stop\n"; } return 0; }
Last edited by Ancient Dragon; Oct 24th, 2008 at 12:57 am. Reason: add code tags
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
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)
top of loop enter variable x1 enter variable x2 are x1 and x2 the same and negative yes, then exit the loop multiply x1 * x2 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.
![]() |
Other Threads in the C++ Forum
- Previous Thread: How to increse the width of the console screen
- Next Thread: Problems passing multidimensional arrays
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist 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 template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






