Question

In: Computer Science

If you execute the code shown below and the user enters the following sales amounts for...

If you execute the code shown below and the user enters the following sales amounts for Region 1: 25000, 30000, 10000, –1, then, the value stored in totRegSales when the inner loop ends will be __________.

int sales = 0;

int region = 1;

int totRegSales = 0;

while (region < 3)

{

   cout << "First sales amount for Region "

        << region << ": ";

   cin >> sales;

   while (sales > 0)

   {

      totRegSales = totRegSales + sales;

      cout << "Next sales amount for Region "

           << region << ": ";

      cin >> sales;

   } //end while

  

   cout << endl << "Region " << region << " sales: $"

        << totRegSales << endl << endl;

   region = region + 1;

   totRegSales = 0;

} //end while

cout << "End of program" << endl;

65000

55000

-1

0

Solutions

Expert Solution

#include<iostream>
using namespace std;
int main()
{
int sales = 0;
int region = 1;
int totRegSales = 0;
while (region < 3)
{
cout << "First sales amount for Region "
<< region << ": ";
cin >> sales; //for eg user enters 25000
while (sales > 0)
{
totRegSales = totRegSales + sales; //0+25000=25000
cout << "Next sales amount for Region "
<< region << ": ";
cin >> sales;// user enters 30000
//now sales>0
//toRegSales=25000+30000=55000
//now user enters sales=10000
//as sales>0
//toRegSales=55000+10000=65000
//now user enters sales=-1
//as sales<0 loop terminates
} //end while
//now after inner loop execution toRegSales=65000
cout << endl << "Region " << region << " sales: $"
<< totRegSales << endl << endl;
region = region + 1;
totRegSales = 0;
} //end while
cout << "End of program" << endl;
}

65000 is correct answer


Related Solutions

Write a java code to ask the user for a string, and assuming the user enters...
Write a java code to ask the user for a string, and assuming the user enters a string containing character "a", your java program must convert all "a" to "b" in the string so for example if user types : "AMAZON" , your program must convert it to "BMBZON" the driver program must ask : enter a string containing "a" or "A" --------- (user enters string) then it should say; HERE IS YOUR NEW STRING ---------- (string with all a's...
Write Java code that allows a user to repeatedly enter numbers. Each time the user enters...
Write Java code that allows a user to repeatedly enter numbers. Each time the user enters a number, the program should print out the average of the last 3 numbers (or all numbers if 3 or less have been entered). I would like a detailed explanation so that a beginner level Java programmer could understand.
Complete the attached code so that if the user enters the number 22 for the number...
Complete the attached code so that if the user enters the number 22 for the number of items purchased and 10.98 for the price of each, the following results are displayed: The total bill is $241.56 Hint: It must include cin and variables. // This program will read the quantity of an item and its price // Then print the total price. // The input will come from the keyboard and the output will go to the monitor. #include <iostream>...
can you please convert this python code into java? Python code is as shown below: #...
can you please convert this python code into java? Python code is as shown below: # recursive function def row_puzzle_rec(row, pos, visited):    # if the element at the current position is 0 we have reached our goal    if row[pos] == 0:        possible = True    else:        # make a copy of the visited array        visited = visited[:]        # if the element at the current position has been already visited then...
Consider the following code fragment and answer below 1. Read(fd, user entry, size of (user entry));...
Consider the following code fragment and answer below 1. Read(fd, user entry, size of (user entry)); 2. Comp=memcmp(userEntry, correct password, stream( user Entry)); 3. If (Comp!=0) 4. Return BAD_PASS - identify any 3 problems with code 8 for each defect describe: - A) what is this problem - B) how it can be found (code, review, Static analysis.....) - C) how it can be solved
1. Convert the following code shown below to C++ code: public class HighwayBillboard { public int...
1. Convert the following code shown below to C++ code: public class HighwayBillboard { public int maxRevenue(int[] billboard, int[] revenue, int distance, int milesRes) { int[] MR = new int[distance + 1]; //Next billboard which can be used will start from index 0 in billboard[] int nextBillBoard = 0; //example if milesRes = 5 miles then any 2 bill boards has to be more than //5 miles away so actually we can put at 6th mile so we can add...
The amounts of financial aid awarded for a population of students are shown below. Using an...
The amounts of financial aid awarded for a population of students are shown below. Using an appropriate graphical technique, state whether you believe that the assumption of normality of this population of aid awards exists. Justify your answer. $8,500 $11,000 $12,400 $9,000 $14,000 $4,500 $12,000 $16,000 $7.500 $11,500 $8.000 $19,000 $10,500 $5,000 $16,500 $9,500 $20,000 $17,500 $8.500 $12,500 $7,000 $19,000 $19,500 $6,000 $13,000
A new accountant at Shamrock, Inc. is trying to identify which of the amounts shown below...
A new accountant at Shamrock, Inc. is trying to identify which of the amounts shown below should be reported as the current asset “Cash and cash equivalents” in the year-end balance sheet, as of April 30, 2019. 1. $60 of currency and coin in a locked box used for incidental cash transactions. 2. A $10,600 U.S. Treasury bill, due May 31, 2019. 3. $275 of April-dated checks that Shamrock has received from customers but not yet deposited. 4. An $86...
Code in Java Given the LinkedList class that is shown below Add the following methods: add(String...
Code in Java Given the LinkedList class that is shown below Add the following methods: add(String new_word): Adds a linkedlist item at the end of the linkedlist print(): Prints all the words inside of the linkedlist length(): Returns an int with the length of items in the linkedlist remove(int index): removes item at specified index itemAt(int index): returns LinkedList item at the index in the linkedlist public class MyLinkedList { private String name; private MyLinkedList next; public MyLinkedList(String n) {...
Using the code below as a template, write a program that asks the user to enter...
Using the code below as a template, write a program that asks the user to enter two integers, and finds and prints their greatest common denominator (GCD) in Java! package cp213; import java.util.Scanner; public class Lab01 { /** * @param a * @param b * @return */ public static int gcd(int a, int b) { // your code here } /** * @param args */ public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int a = 0;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT