Thursday, July 9, 2009

C ++ code answer of....?

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

C ++ code answer of....?
#include%26lt;iostream%26gt;





using namespace std;





int main()


{


int max,min,count = 0,date = 10;


int *array = new int[];


cout%26lt;%26lt;"Please enter max num";


cin%26gt;%26gt;max;


cout%26lt;%26lt;"\n"%26lt;%26lt;"Please enter min num";


cin%26gt;%26gt;min;





while(date !=0)


{


cout%26lt;%26lt;"Please enter date";


cin%26gt;%26gt;date;


array[count] = date;


count ++;


}


int sumin=0,sumout=0;


for(int i=0;i%26lt;count;i++)


{


if(array[i] %26lt; max %26amp;%26amp; array[i] %26gt; min)


sumin += array[i];


else


sumout += array[i];


}


cout%26lt;%26lt;"Sum in"%26lt;%26lt;sumin%26lt;%26lt;" sum out"%26lt;%26lt;sumout;


int i = 0;


cin%26gt;%26gt;i;





}
Reply:#include %26lt;iostream.h%26gt;





#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%26lt;%26lt;"Enter data";


cin%26gt;%26gt;iInputValue;





if(iInputValue==0) break;





if((iInputValue%26gt;=LowRange) %26amp;%26amp; (iInputValue%26lt;=HighRange))


{


iSum_in_range+=iInputVale;


}


else


{


iSum_out_range+=iInputValue;


}


}





cout%26lt;%26lt;"Sum of in range values: "%26lt;%26lt;iSum_in_range%26lt;%26lt;endl;


cout%26lt;%26lt;"Sum of out of range values: "%26lt;%26lt;iSum_out_range%26lt;%26lt;endl;


}





That's all...


No comments:

Post a Comment