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!!

#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;
}

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

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.