Friday, July 31, 2009

Plz help with this c++ program?

a. Write a pseudo-code that prompt the user to input number of old items and then receive the sold value for each item, calculate the average value, display the items numbers associated with its values and display also the calculated average value on the screen.





b. write down the C++ code for the previous program.





Well... I tried to solve it and here we go:





* Pseudo-code:


start


get sold items,sold value


average=sold value/sold items


Display sold items,sold value


Display average





* C++:





#include%26lt;iostream.h%26gt;


void main()


{


int NumOfSold,SolValue;


float average;


cout%26lt;%26lt;"enter the number of sold items\n";


cin%26gt;%26gt;NumOfSold;


cout%26lt;%26lt;"enter the sold value for each item\n";


cin%26gt;%26gt;SolValue;


average=(float)SolValue/NumOfSold;


cout%26lt;%26lt;NumOfSold%26lt;%26lt;":"%26lt;%26lt;SolValue%26lt;%26lt;endl;


cout%26lt;%26lt;"average:"%26lt;%26lt;average;


}

Plz help with this c++ program?
So, what is the result?
Reply:Did you run it to see if it works? If it works, then it's right, if it doesn't, then you'll have to debug things to make it work.





After looking at it for 2 seconds, it looks right, but that doesn't mean it is. The only way to be sure is to compile it and test it.


No comments:

Post a Comment