Question

In: Computer Science

Create a program that asks the user for the names of two car dealerships and the...

Create a program that asks the user for the names of two car dealerships and the # of cars sold in each one.

Then output that data in two columns as shown below.

The "Store location" column has a width of 25, while the "Cars sold" column has a width of 9.

Also, notice the alignment of the second column.

The program should end with the "Press Enter to end this program" prompt.

OUTPUT

Enter the location for the first store: [user types: West Kendall]

Enter the total # of cars sold in the current month: [user types: 89]

Enter the location for the second store: [user types: Miami Lakes]

Enter the total # of cars sold in the current month: [user types: 104]

STORE LOCATION CARS SOLD
West Kendall 89
Miami Lakes 104

Press Enter to end this program

Starter Code:

#include <iostream>
#include <string>
//include need directive

int main() {

// VARIABLES
std::string store1 = "";
std::string store2 = "";
int sales1 = 0;
int sales2 = 0.0;

// INPUT
"Enter the location for the first store: "
  
std::cout << std::endl;//needed for Mimir
"Enter the total # of cars sold in the current month: "
  
std::cout << std::endl;//needed for Mimir

std::cout << "Enter the location for the second store: "
//hint check if you need to ignore
  
  
std::cout << std::endl;//need for Mimir
"Enter the total # of cars sold in the current month: "

std::cout << std::endl;//need for Mimir

// OUTPUT
// OUTPUT
std::cout << std::endl;//need for Mimir
"STORE LOCATION" << "CARS SOLD"
  

"\nPress Enter to end this program"
//Hint use a combination of ignore() and get()

return 0;
}

Solutions

Expert Solution

The program is given below: that take names of two car dealerships and the # of cars sold in each one, print formatted output where STORE LOCATION has width of 25 while CARS SOLD has width of 9, then press enter to end this program.

#include <iostream>
#include <string>
#include<iomanip>
using namespace std;
int main() {
string store1 ="";
string store2 = "";
int sales1 = 0;
int sales2 = 0.0;

//take location of first store from user
cout<<"Enter the location for the first store: ";
getline(cin,store1);
//take total no of cars sold
cout<<"Enter the total # of cars sold in the current month: ";
cin>>sales1;
cin.ignore();
//take location of second store from user
cout<<"Enter the location for the second store: ";
getline(cin,store2);
/**if user press enter without entering any value for second store2
that means store2 is empty so dont take no of cars sold**/
//if store2 is not empty
if(!store2.empty())
{ //take no of cars sold
cout<<"Enter the total # of cars sold in the current month: ";
cin>>sales2;
}
//print formatted output
cout<<left<<setw(25)<<"STORE LOCATION"<<left<<setw(9)<<"CARS SOLD";
cout<<"\n"<<left<<setw(25)<<store1<<setw(9)<<sales1;
cout<<"\n"<<left<<setw(25)<<store2<<setw(9)<<sales2;
  
//press enter to end this program
cout<<"\nPress Enter to end this program";
cin.ignore().ignore();
return 0;
}

The screenshot of code is given below:

Output Example 1:

Output Example 2: (here you can see that name for store2 is empty and sales2 is 0 because user has press enter for second store that means it does not want to enter value so print default setted values).


Related Solutions

Create a Java program that asks a user to enter two file names. The program will...
Create a Java program that asks a user to enter two file names. The program will read in two files and do a matrix multiplication. Check to make sure the files exist. first input is the name of the first file and it has 2 (length) 4 5 6 7 Second input is the name of the second file and it has 2 (length) 6 7 8 9 try catch method
Create a Linux program that asks two scores from the user, specifically the raw score as...
Create a Linux program that asks two scores from the user, specifically the raw score as the first score and the total score as the second score. Store the digits in the EAX and EBX register, respectively. Given the formula raw score divided by total score times 50 and plus 50. Store the result in memory location ‘res’ and finally display the result.
Create an application named Rusty2 that asks the user for the dealer cost of a car,...
Create an application named Rusty2 that asks the user for the dealer cost of a car, and the cleaning cost, and then displays the retail cost. Your application should simply send the dealer cost and cleaning cost to the getRetailPrice method in the Dealership class to obtain the retail cost. here below is the dealership class code amd meed to create rusty2 code import java.util.Calendar; public class Dealership { // public static final class variables public static final int YEAR_STARTED...
Using C++ Create a program that asks the user to input a string value and then...
Using C++ Create a program that asks the user to input a string value and then outputs the string in the Pig Latin form. - If the string begins with a vowel, add the string "-way" at the end of the string. For “eye”, it will be “eye-way”. - If the string does not begin with a vowel, first add "-" at the end of the string. Then rotate the string one character at a time; that is, move the...
IN JAVA Create a program that asks the user to input the day, high and low...
IN JAVA Create a program that asks the user to input the day, high and low temperature. Display the day, high, and low. Use a While Loop to enter all seven days of the week and high temperatures. Inside the While Loop, the program will count, total, and average the highs. The following will be displayed:                         Day: (variable)                         High: (variable)                         Count High: (variable)                         Total High: (variable)                         Average High: (variable) After the seven days and highs...
IN JAVA Create a program that asks the user to input the day, high and low...
IN JAVA Create a program that asks the user to input the day, high and low temperature. Display the day, high, and low. Use a While Loop to enter all seven days of the week and high temperatures. Inside the While Loop, the program will count, total, and average the highs. The following will be displayed:                         Day: (variable)                         High: (variable)                         Count High: (variable)                         Total High: (variable)                         Average High: (variable) After the seven days and highs...
Create a program that asks the user to input three numbers and computes their sum. This...
Create a program that asks the user to input three numbers and computes their sum. This sounds simple, but there's a constraint. You should only use two variables and use combined statements. You can use the output below as a guide. Please enter the first number: 4 Please enter the second number: 2 Please enter the third number: 9 The sum of the three numbers is: 15.
Using RAPTOR create a program that allows the user to input a list of first names...
Using RAPTOR create a program that allows the user to input a list of first names in on array and last names into a parallel array. Input should be terminated when the user enters a sentinel character. the output should be a list of email address where the address is of the following form: [email protected]
Write a program that asks the user to type in two integer values. Test these two...
Write a program that asks the user to type in two integer values. Test these two numbers to determine whether the first is evenly divisible by the second and then display the appropriate message to the terminal. Objective C
in.java Two companies donated money on two occasions. Write a program that: asks for 2 names...
in.java Two companies donated money on two occasions. Write a program that: asks for 2 names of companies aks how much each of the given companies donated for Christmas. aks how much each of the given companies donated for school support prints the total donations for Christmas prints the total donations for school support prints which one of 2 companies donated more money in general. For clarity, in the sample runs below, the user input is shown in blue. The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT