#include %26lt;iostream.h%26gt;
#include %26lt;stdlib.h%26gt;
using namespace std;
int getstockprices;
float printAverage;
float printLowest;
float printhighest;
void get_stock_price(float %26amp;stockprice)
cout%26lt;%26lt;"Please enter the closing stock price for day 1." %26lt;%26lt; endl;
cin%26gt;%26gt; stockprice;
int main()
{
int stockprice;
float average;
float lowest;
float highest;
int day;
for(day = 0; day %26lt; 31; day++)
{
float stockprice;
float getstockprice(stockprice);
cout %26lt;%26lt; "1st price: " %26lt;%26lt; stockprice %26lt;%26lt; endl;
void
if min%26gt;current entered price)
min=currententeredprice;
min_day=day;
if (max %26lt; current entered price)
max=current entered price;
max_day=day;
system("PAUSE");
return 0;
}
it's not compiling what am i doing wrong. please help.
write, compile and run a C++ program with proper style and functions to read 31days worth of closing stock prices from a user. after accepting 31days worth of stock prices, the program will output:
highes price
lowest price
average price
C++ programing computer science?
You're implementing your function wrong to begin with. Declare it like this:
void get_stock_price(float %26amp;stockprice);
And then implement the function after the main like so:
void get_stock_price(float %26amp;stockprice)
{
cout%26lt;%26lt;"Please enter the closing stock price for day 1." %26lt;%26lt; endl;
cin%26gt;%26gt; stockprice;
}
Also, get rid of the line that just says "void".
Additionally, your if statements need brackets:
if (min%26gt;currententeredprice)
{
min=currententeredprice;
min_day=day;
}
Do the same thing for the max
Hope that helps
Reply:It seems you have a stray keyword, in your for loop. Get rid of that 'void' in your loop.
Also, try this logic:
float stockprice;
float min = 0;
float max= 0;
float avg = 0;
float total = 0;
for(int x = 0; x %26lt; 31; x++)
{
cout%26lt;%26lt;"Please enter the closing stock price for day "%26lt;%26lt;x+1%26lt;%26lt;": "%26lt;%26lt;endl;
cin%26gt;%26gt;stockprice;
if(stockprice %26gt; max)
max = stockprice;
if(stockprice %26lt; min)
min = stockprice;
else if(x==0)
min = stockprice;
total += stockprice;
}
cout%26lt;%26lt;"Highest Price: "%26lt;%26lt;max%26lt;%26lt;endl;
cout%26lt;%26lt;"Lowest Price: "%26lt;%26lt;min%26lt;%26lt;endl;
cout%26lt;%26lt;"Average Price: "%26lt;%26lt;total/31.0%26lt;%26lt;endl;
Reply:"it's not compiling what am i doing wrong"
Don't know; you didn't bother to post the compiler error!
Bean:
S/He is also missing parenthesis, has undeclared variables, and since there is no indentation in his post, may be missing proper block layout.
snow of june
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment