### Calculate Stock Value using an inline function

I am soooo lost. Please help me. I have to write a program which uses an inline function calculateStockValue. the function takes two parameters - one is a number of shares and the other is unit price of a share. User should be able to use this function as many times as he wants unless he wants to quit. (loop here???) Once user has completed entering data, the program should be able to provide a feedback to the user about his total account value (sum of all the values of the shares). It says I also have to write a test program (main function) to test the working of the code.

There's so much of this I don't understand. So, for starters, how do I accumulate the stock shares and their related prices?

Here's what I have so far...

 ``1234567891011121314151617181920212223242526`` ``````//inline.cpp -- using an inline function #include using namespace std; //an inline function definition inline float calculatedStockValue(unsigned int shares, float price) { return(shares*price); } main () { unsigned int Portfolio (void) unsigned int StockShares; float StockPrice; float value = StockShares * StockPrice; cout<<"Please enter the number of shares of your first stock: "; cin>>StockShares; cout<<"Please enter the price of the stock: "; cin>>StockPrice; cout<<"Your total stock value is "<
 ``1234567891011121314151617181920212223`` ``````inline float calcualteStockValue(unsigned int shares,float price) { return shares*price; } main declare variables int shares; float price; char response; intialize total=0; do { get shares and price from user;(cin) calcualte stock value and add it to total ask user does he want continue; get response from user(cin) response=tolower(response); }while(response=='y'); output total; ``````
Thank you so much for responding!

With your suggestions, I've changed it to this below. Can you tell me why it is telling me that line 20, total, is an error, expression must have integer or enum type?

 ``123456789101112131415161718192021222324252627`` ``````#include using namespace std; inline float calculateStockValue(unsigned int shares,float price) { return shares*price; } int main () { int shares; float price; char response; float total=0; do { cout<<"Please enter the number of shares of your first stock: "; cin>>shares; cout<<"Please enter the price of the stock: "; cin>>price; total = calculateStockValue + total; cout << "Would you like to enter a new stock ? [y/n] "; cin >> response; response=tolower(response); } while(response=='y'); cout<<"The current value of your Stock Portfolio is "<
You don't have any parameters in your calculateStockValue call. Pass shares and price in like this:
 `` `` ``calculateStockValue(shares, price)``
You did it! You got it working!!! WOW...thank you soooo very much.

Last question if you don't mind. Part of the lab says I also have to write a test program (main function) to test the working of the code.

I have no idea what that actually means. Isn't the main function already running the inline function in the code? Is that what those instructions sound like to you? Or is there something else I'm supposed to include?

Again, thank you!!!
Sounds like he just wants you to thouroughly test the code. I don't really know what more he would want other than what you have; it seems to pretty much do what it's supposed to.
Thank you both so very much!!!
Topic archived. No new replies allowed.