I have to write a program to read 10 integers into an array. It will then read in one more integer. My program should then compute and output how many distinct pairs of integers in the array add up to the last number that was input. Note I cannot use the same number twice in a sum, unless it has been input two or more times.

How do I go about doing this?

I really don't know how to go about doing this, I know that I have to have the program promt you to input 10 numbers, and then I have to get the program to compare all the possible sums of two of the integers and then say if they equal 9.

So far I have:

#include <iostream.h>
#include <stdlib.h>

int main()
{
int num, count;
int List[10],i;

// input 10 integers into an array and compute the average
for (i=0;i<10;i++)
{
cout << "Please enter an integer ";
cin >> List ;


But I don't know where to go from here

>> Try to use Codes in Coding tags
>> Try to use cout statement out of looping statement .

#include<iostream>
           #include<conio>
           int main()
 {
int arr[10];
   int i,j,sum=0,flag;
     
	cout<<"Enter the Integers : ";
	  for(i=0;i<10;i++)
	     cin>>arr[i];  //Loop Takes ten integer 
	       for(i=0;i<10;i++)
	  { 
	      flag=0;                   // Flag is assigned 0 intially
	     for(j=i+1;j<10;j++)                   
	      if(arr[i]==arr[j])         // Any integer repeat then flag becomes 1   
	     flag=1;                         
	   if(flag==0)                    //If any integer is repeated then it is not counted
	  sum=sum+arr[i];
	  }
	 cout<<" Sum is :"<<sum;             //Sum is displayed
       
     return 0;
}

I think it might help 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.