This program is supposed to print the sum, average, product, smallest and largest of three numbers. Please look at this and tell me where I am going wrong.

Recommended Answers

All 7 Replies

Member Avatar for iamthwee

It looks good 2 me that is how i will do it ;)

To print the smallest you could do is num1<num2, then is num1<num3. Or somethink like that. Sorrie i am not to sure.

after looking at the code i have spotted a few mistakes, first of all you cannot re-declare variables, like when you have

int number1;
int number2;
.....

...
..
int number1;
int number2;

you are declaring these twice, if you want to use the same variable for each section only declare them once and then re-use them, or you could change the names so they relate to each section, such as

int sum_number1;
int sum_number2;
...
...
int product_number1;
int product_number2;

and so on

Secondly, you seem to have repeated yourself with declaring

using std::cout;
using std::cin;
using std::endl;

im not sure how erroneous this is but it returned many errors on the dev-c++ compiler.
Im sure that the more experienced programmers aroundhere will be able to explain and spot errors a lot better than me, but that is all i could seem to find at the moment

from your original code i have went through and got it working, how i would write it, go ahead and change what you need

#include <iostream.h> 
int number1;
int number2;
int number3;
int sum;
int prod;
int avg;

int main()
{
	cout << "Enter first integer: ";
	cin >> number1; 

	cout << "Enter second integer: "; 
	cin >> number2; 

	sum = number1 + number2;

	cout << "Sum is " << sum << endl;

			cout << "Enter two integers to compare: "; 
			cin >> number1 >> number2;
	
			if ( number1 == number2 )
				cout << number1 << " == " << number2 << endl;

			if ( number1 != number2 )
				cout << number1 << "!= " << number2 << endl;

			if ( number1 < number2 )
				cout << number1 << " < " << number2 << endl;

			if ( number1 > number2 )
				cout << number1 << " > " << number2 << endl;

			if ( number1 <= number2 ) 
				cout << number1 << " <= " << number2 << endl;
	
			if ( number1 >= number2 )
				cout << number1 << " >= " << number2 << endl;
	

					
					cout << "Enter first integer: "; 
					cin >> number1; 

					cout << "Enter second integer: "; 
					cin >> number2;

					cout << "Enter third integer: ";
					cin >> number3;

                    avg = (number1 + number2 + number3)/3;
					cout << "Average is " << avg << endl;
	
						
							cout << "Enter first integer: "; 
							cin >> number1;

							cout << "Enter second integer: ";
							cin >> number2; 

							cout << "Enter third integer: "; 
							cin >> number3; 
	
                             
                            prod = (number1*number2*number3);
							cout << "Product is " << prod << endl;											
							return 0;			
}

thanks it is starting to make a little more sense to me now. I thought that I had to enter "return 0" after each program. Do you know and understand the concept of an UML, actors, and use cases. I have read and reread the section in my book, but still do not understand how to do an extra credit report where I am assuming that someone has a Superstore that sells perpheriphal, hardware, etc. What are the actors and major uses cases in this situation????

no problem, hmm UML and actors etc, ive never really heard of, i dont go into much concept detail since i am learning to program off my own back and cant be bothered going into that much detail about things at the minute, but i will have a look around and i will post again if i understand any of it

after a few minutes looking on the web for uml etc i have found this website: http://www.agilemodeling.com/artifacts/useCaseDiagram.htm It descibes teh terms and the situation quite well, from first glance it seems to me that this is all about the design stage of creating a program and how to document it properly

thanks a lot for all your help. Hopefully this will put me where I need to be again many thanks to you

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.