using an inline function to calcualte stock value

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//inline.cpp -- using an inline function
#include <iostream>
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 "<<calculatedStockValue();
return ();
} 
Yes, you would have the function call in a loop. To store the value, simply make a float variable outside of the loop initialized to 0, and the inside the loop whenever the function is called add the result to the variable.
Oh my goodness, thank you so much for replying!!! I have put in so much time on this and have no one to lead me in the right direction.

So, I added a loop below and what I think is an exit for the loop. I'm still getting fail error. I know this code is messed up. Any advice is greatly appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//inline.cpp -- using an inline function
#include <iostream>
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;
do
{ 
cout<<"Please enter the number of shares of your first stock: ";
cin>>StockShares;
cout<<"Please enter the price of the stock: ";
cin>>StockPrice;
char choice;
    cout << "Would you like to enter a new stock ? [y/n] ";
    cin >> choice;
while (choice == 'y' || choice == 'Y');
}
 
cout<<"Your total stock value is "<<calculatedStockValue();
return ();
}


1>------ Build started: Project: Lab4, Configuration: Debug Win32 ------
1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup
1>C:\Users\fgower\Documents\Visual Studio 2010\Projects\Lab4\Debug\Lab4.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on
Somehow or another, my source file wasn't part of the project. So I added it as a new item and now I'm getting different errors:

1>------ Build started: Project: Lab4, Configuration: Debug Win32 ------
1> calculatedStockValue.cpp
1>c:\users\fgower\documents\visual studio 2010\projects\lab4\lab4\calculatedstockvalue.cpp(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\fgower\documents\visual studio 2010\projects\lab4\lab4\calculatedstockvalue.cpp(16): error C2144: syntax error : 'unsigned int' should be preceded by ';'
1>c:\users\fgower\documents\visual studio 2010\projects\lab4\lab4\calculatedstockvalue.cpp(31): error C2061: syntax error : identifier 'cout'
1>c:\users\fgower\documents\visual studio 2010\projects\lab4\lab4\calculatedstockvalue.cpp(32): error C2059: syntax error : ')'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Topic archived. No new replies allowed.