In: Computer Science
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;
}
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).