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

#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;
}
2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Ancient Dragon
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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.