Question

In: Computer Science

Why is the output for LowestSales a negative number? I am using Visual Studio. _______________________________________*_________________________________________ int...

Why is the output for LowestSales a negative number? I am using Visual Studio.

_______________________________________*_________________________________________

int main()
{
   const int STORE = 10;
   double Sales[STORE];//array for sales
   double HighestSales = Sales[], LowestSales = Sales[]; //arrays to capture highest and lowest sales
   double AverageSale = 0.00; //stores average sale amount

   for (int i = 0; i < 10; i++) // gather sales from 10 stores
   {
       cout << "Enter Store " << (i + 1) << " daily sales: \n";
       cin >> Sales[i]; //prompt the user to enter the daily sales
  
       int HighStoreNo = 0, LowStoreNo = 0; //initialize variables for high store number and low store number

       if (HighestSales > Sales[i] && (isdigit(Sales[i]) != 0) //check to see if this the highest sale, and check for positive integer
       {
           HighestSales = Sales[i]; //assign value to array member to store 'highest sales'
           HighStoreNo = i; //if highest value, assign stored value
       }
       if    (LowestSales <= Sales[i] && (isdigit(Sales[i]) != 0); //assign value to array member to store 'lowest sales'
               LowestSales = Sales[i];
               LowStoreNo = i;   //if lowest value, assign stored value
       }
  
   AverageSale += Sales[i]; //keep accumulating sales total

   }
   cout << fixed << showpoint << setprecision(2);//sets output precision to two decimals
   AverageSale = AverageSale/10; //calculate the average sale by dividing by 10 stores
  
   cout << "Highest Sale: " << HighestSales << ", Store number: " << (HighStoreNo + 1) << endl; //highest sale
   cout << "Lowest Sale: " << LowestSales << ", Store number: " << (LowStoreNo + 1) << endl; //lowest sale
   cout << "Average Sale: " << AverageSale << endl; //average sale

Solutions

Expert Solution

Code - corrected

#include <iostream>
#include <cctype>
#include <iomanip>
using namespace std;

int main()
{
const int STORE = 10;
double Sales[STORE];//array for sales
double HighestSales =0, LowestSales = 999999; //arrays to capture highest and lowest sales
double AverageSale = 0.00; //stores average sale amount
   int HighStoreNo = 0, LowStoreNo = 0; //initialize variables for high store number and low store number

for (int i = 0; i < 10; i++) // gather sales from 10 stores
{
cout<< "Enter Store " << (i + 1) << " daily sales: \n";
cin>> Sales[i]; //prompt the user to enter the daily sales
  
HighStoreNo = 0;
       LowStoreNo = 0; //initialize variables for high store number and low store number

if(HighestSales < Sales[i] && Sales[i]>=0) //check to see if this the highest sale, and check for positive integer
{
HighestSales = Sales[i]; //assign value to array member to store 'highest sales'
HighStoreNo = i; //if highest value, assign stored value
}
if(LowestSales > Sales[i] && Sales[i]>=0){ //assign value to array member to store 'lowest sales'
LowestSales = Sales[i];
LowStoreNo = i; //if lowest value, assign stored value
}
  
AverageSale += Sales[i]; //keep accumulating sales total

}
cout<< fixed << showpoint << setprecision(2);//sets output precision to two decimals
AverageSale = AverageSale/10; //calculate the average sale by dividing by 10 stores
  
cout<< "Highest Sale: " << HighestSales << ", Store number: " << (HighStoreNo + 1) << endl; //highest sale
cout<< "Lowest Sale: " << LowestSales << ", Store number: " << (LowStoreNo + 1) << endl; //lowest sale
cout<< "Average Sale: " << AverageSale << endl; //average sale

return 0;
}

Screenshots -

pls do give a like , thank you


Related Solutions

USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some time and still can't quite figure it out. I'm creating an app that has 2 textboxes, 1 for inputting customer name, and the second for entering the number of tickets the customer wants to purchase. There are 3 listboxes, the first with the days of the week, the second with 4 different theaters, and the third listbox is to display the customer name, number...
I am trying to write code for a program in Visual Studo using Visual Basic programming...
I am trying to write code for a program in Visual Studo using Visual Basic programming language that computes the factorial of an entered number by using a For Loop. My problem is that it keeps re-setting the variable for Factorial. Below is my code if anyone can help. I want it to multiply the given number by that number - 1, then continuing to do so until it hits zero without multiplying by zero. Private Sub BtnCalculate_Click(sender As Object,...
I am having trouble fixing my build errors. The compiler I am using is Visual Studio.Thanks....
I am having trouble fixing my build errors. The compiler I am using is Visual Studio.Thanks. #include <iostream> #include <string> #include <cstdlib> using namespace std; /* * structure to store employee details * employee details are stored as linked list */ struct Employee { private:    string full_name; //full name    double net_income; //income public:    struct Employee *next; //pointing to the next employee details in the list                        /*                   ...
Create a Visual Studio console project (c++) containing a main() program that declares a const int...
Create a Visual Studio console project (c++) containing a main() program that declares a const int NUM_VALUES denoting the array size. Then declare an int array with NUM_VALUES entries. Using a for loop, prompt for the values that are stored in the array as follows: "Enter NUM_VALUES integers separated by blanks:" , where NUM_VALUES is replaced with the array size. Then use another for loop to print the array entries in reverse order separated by blanks on a single line...
Create an ASP.Net Website using Visual Studio with Visual Basic.Net: Create a simple calculator that has...
Create an ASP.Net Website using Visual Studio with Visual Basic.Net: Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results Create 4 buttons to add, subtract, multiply, and divide Prevent the user from entering text in the number fields Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box Create two additional buttons: - One to store...
Write a C program The Visual Studio project itself must make its output to the Console...
Write a C program The Visual Studio project itself must make its output to the Console (i.e. the Command Prompt using printf) and it must exhibit the following features as a minimum: 3%: Looping Menu with 3 main actions: View Cars, Sell Car, View Sales Note: A Car is defined by its price and model 3%: Must contain at least three arrays to record sales figures (maximum of 10 Car models) Two for recording the price and model of one...
Show the output of the following code segment. int count=0;                         for (int i=2; i <=...
Show the output of the following code segment. int count=0;                         for (int i=2; i <= 4; i++ ) {                                     StdOut.println(i);                                     for (int j=1; j <3; j++) {                                                 count++;                                                 StdOut.println(i +" " + j +" "+ count);                                     }                         } count i j I print 0 2 1 3 1 1 1 2 3 2 2 3 3 3 3 4 3 Show the output of the function call statements shown.             double x =...
The output of the following code is "11 0" But I am not sure why, can...
The output of the following code is "11 0" But I am not sure why, can someone please explain to me clearly and concisely why this is the case? main(){ int n=1; if(fork()) wait(&n); else n=n+10; printf("%d\n", n); exit(0); }
C# ( asp.net ) 2019 visual studio I have a dropdown option. If I choose "date"...
C# ( asp.net ) 2019 visual studio I have a dropdown option. If I choose "date" option, I get to enter list of dates like 02/08/1990, 06/14/1890 in (mm/dd/YYYY) format. How can I sort these dates in ascending order?. Can you provide me some code. Thank you
Using Visual Studio in C#; create a grading application for a class of ten students. The...
Using Visual Studio in C#; create a grading application for a class of ten students. The application should request the names of the students in the class. Students take three exams worth 100 points each in the class. The application should receive the grades for each student and calculate the student’s average exam grade. According to the average, the application should display the student’s name and the letter grade for the class using the grading scheme below. Grading Scheme: •...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT