This is the assingment in its exact words. \"Create a C++ project that lets the
ID: 3872543 • Letter: T
Question
This is the assingment in its exact words.
"Create a C++ project that lets the user to enter the stock price it closed for any number of days.
Use a sentinel value you choose. If the sentinel value is the first you enter, give a message “NO stock was entered!”. Use a counter to keep the number of the stock price entries and an accumulator for the total of all entries.
When the user finishes entering the prices, calculate the average and display it on the screen"
i have to run it through my visual studio.
Explanation / Answer
using namespace std;
int main(){
double sum;
double price;
int count = 0;
cout << "Enter stock prices and -1 to stop:" << endl;
sum = 0;
do {
cin >> price;
if (price == -1)
break;
count++;
sum = sum + price;
} while(1);
if (count == 0){
cout << "No stock was entered ";
}
else {
cout << "The average stock price is " << sum/count << endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.