To ask the user to enter anything you'd need to implement the scanner and track what they say. You can store each individual sale in a variable and assign it to the array index; in a loop:
(while there's sales inputted)
sales_arr[i] = user_sale_val;
num_sales++; //should be 7 at the end, since it's for a week
//have code to reset variable and get next sale value
user_sale_val being an integer and
sales_arr being an int array of size 10, just in case.
For adding all the values together in the array, you could exit the for loop by returning. An if condition can be there to check if there are any more input values. If not, we can add an if loop as such:
if (num_sales = 7) { //for a week
index = 0; //will only go up to 6, since index starts at 0.
total_sales = total_sales + sales_arr[index]; //adding to prev. total
}
Be sure to declare the variables before using them! These are only examples.
how do you design a program that asks the user to enter a store's sales for each day of the week. the amount should be stored in an array. use a loop to calculate the total sales for the week and display the result.
1 answer