English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Write a program that asks the user for the low and high integer in a range of integers. The program then asks the user for integers to be added up. The program computes two sums:
•The sum of integers that are in the range (inclusive),
•and the sum of integers that are outside of the range.
The user signals the end of input with a 0.
In-range Adder
Low end of range:
20
High end of range:
50
Enter data:
21
Enter data:
60
Enter data:
49
Enter data:
30
Enter data:
91
Enter data:
0
Sum of in range values: 100
Sum of out of range values: 151

I need the C++ code of this by march 8.. help me pls....

2007-03-06 20:21:12 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

2 answers

#include

using namespace std;

int main()
{
int max,min,count = 0,date = 10;
int *array = new int[];
cout<<"Please enter max num";
cin>>max;
cout<<"\n"<<"Please enter min num";
cin>>min;

while(date !=0)
{
cout<<"Please enter date";
cin>>date;
array[count] = date;
count ++;
}
int sumin=0,sumout=0;
for(int i=0;i {
if(array[i] < max && array[i] > min)
sumin += array[i];
else
sumout += array[i];
}
cout<<"Sum in"< int i = 0;
cin>>i;

}

2007-03-06 21:03:46 · answer #1 · answered by Anonymous · 0 0

#include

#define LowRange 20
#define HighRange 50

void main(void)
{
int iSum_in_range=0;
int iSum_out_range=0;
int iInputValue=1;

while(1)
{
cout<<"Enter data";
cin>>iInputValue;

if(iInputValue==0) break;

if((iInputValue>=LowRange) && (iInputValue<=HighRange))
{
iSum_in_range+=iInputVale;
}
else
{
iSum_out_range+=iInputValue;
}
}

cout<<"Sum of in range values: "< cout<<"Sum of out of range values: "< }

That's all...

2007-03-07 04:35:29 · answer #2 · answered by QuizBox 2 · 0 0

fedest.com, questions and answers