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 program that asks the user for two positive integers. If the user's input for...
Create a program that asks the user for two positive integers. If the user's input for either integer is not positive (less than or equal to 0), re-prompt the user until a positive integer is input. You may assume that all inputs will be integers. Print out a list, ascending from 1, of all divisors common to both integers. Then, print out a message stating whether or not the numbers are "relatively prime" numbers. Two positive integers are considered relatively...
11. First and Last Design a program that asks the user for a series of names...
11. First and Last Design a program that asks the user for a series of names (in no particular order). After the final person's name has been entered, the program should display the name that is first alphabetically and the name that is last alphabetically. For example, if the user enters the names Kristin, Joel, Adam, Beth, Zeb, and Chris, the program would display Adam and Zeb. #Sentinel value is DONE SENTINEL = "DONE" ls = [] prompt = "Enter...
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...
Q1 Create a program that asks the user to input their budget. Then, it will ask...
Q1 Create a program that asks the user to input their budget. Then, it will ask the user to input each of their purchase until their entire budget is used up. What kind of loop do you think is the most appropriate? You don't have to create the entire program. Part of it has already been created for you (see code below). Note: Assume that the user always uses up their budget to the last cent and they don't over...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT