// MichiganCities.cpp - This program prints a message for invalid cities in Michigan. // Input: Interactive // Output: Error message or nothing #include #include using namespace std; int main() { // Declare variables string inCity; // name of city to look up in array const int NUM_CITIES = 10; // Initialized array of cities string citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"}; bool foundIt = false; // Flag variable int x; // Loop control variable // Get user input cout << "Enter name of city: "; cin >> inCity; // Write your loop here // Write your test statement here to see if there is // a match. Set the flag to true if city is found. // Test to see if city was not found to determine if // "Not a city in Michigan" message should be printed. return 0; } // End of main()

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 16PE
icon
Related questions
Question
// MichiganCities.cpp - This program prints a message for invalid cities in Michigan.  
// Input:  Interactive
// Output:  Error message or nothing

#include <iostream>
#include <string>
using namespace std;

int main() 
{
   // Declare variables
   string inCity;   // name of city to look up in array
   const int NUM_CITIES = 10;
   // Initialized array of cities
   string citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"}; 
   bool foundIt = false;  // Flag variable
   int x;         // Loop control variable

   // Get user input
   cout << "Enter name of city: ";
   cin >> inCity; 
  
   // Write your loop here  
   
      // Write your test statement here to see if there is 
      // a match.  Set the flag to true if city is found. 
      
   
      
      
   // Test to see if city was not found to determine if 
   // "Not a city in Michigan" message should be printed. 
    
  
   return 0;  

} // End of main() 
Parallel Arrays
JumpinJive.cpp
Co a n you wilele to wite your ɔlateiiemLS.
1 // JumpinJava.cpp
21/ Input:
3 // Output: Name and price of coffee orders or error message if add-in is no
This program looks up and prints the names and prices a
dy Tools
Interactive
Instructions
4.
5 #include <iostream>
1. Study the prewritten code to make sure you
6 #include <string>
understand it.
7 using namespace std;
5 Tips
8.
2. Write the code that searches the array for the name
9 int mainO
Tips
of the add-in ordered by the customer.
10 {
11
// Declare variables.
3. Write the code that prints the name and price of the
12
string addIn;
const int NUM ITEMS = 5; // Named constant
no.
W Add-in ordered
add-in or the error message, and then write the
13
code that prints the cost of the total order.
14
// Initialized array of add-ins
string addIns[]
V/ Initialized array of add-in prices
15
{"Cream", "Cinnamon", "Chocolate", "Amaretto", "Whiskey"};
4. Execute the program by clicking the Run button at
16
17
double addInPrices[]
bool foundIt = false;
the bottom of the screen. Use the following data:
= {,89, .25, .59, 1.50, 1.75};
18
// Flag variable
// Loop control variable
boxes
Cream
19
int X;
20
double orderTotal
2.00; // All orders start with a 2.00 charge
21
Caramel
22
// Get user input
Whiskey
23
cout << "Enter coffee add-in or XXX to quit: ";
ck
24
cin >> addIn;
chocolate
25
26
// Write the rest of the program here.
Chocolate
27
return O;
28 }// End of main()
Cinnamon
29
Vanilla
!!
Transcribed Image Text:Parallel Arrays JumpinJive.cpp Co a n you wilele to wite your ɔlateiiemLS. 1 // JumpinJava.cpp 21/ Input: 3 // Output: Name and price of coffee orders or error message if add-in is no This program looks up and prints the names and prices a dy Tools Interactive Instructions 4. 5 #include <iostream> 1. Study the prewritten code to make sure you 6 #include <string> understand it. 7 using namespace std; 5 Tips 8. 2. Write the code that searches the array for the name 9 int mainO Tips of the add-in ordered by the customer. 10 { 11 // Declare variables. 3. Write the code that prints the name and price of the 12 string addIn; const int NUM ITEMS = 5; // Named constant no. W Add-in ordered add-in or the error message, and then write the 13 code that prints the cost of the total order. 14 // Initialized array of add-ins string addIns[] V/ Initialized array of add-in prices 15 {"Cream", "Cinnamon", "Chocolate", "Amaretto", "Whiskey"}; 4. Execute the program by clicking the Run button at 16 17 double addInPrices[] bool foundIt = false; the bottom of the screen. Use the following data: = {,89, .25, .59, 1.50, 1.75}; 18 // Flag variable // Loop control variable boxes Cream 19 int X; 20 double orderTotal 2.00; // All orders start with a 2.00 charge 21 Caramel 22 // Get user input Whiskey 23 cout << "Enter coffee add-in or XXX to quit: "; ck 24 cin >> addIn; chocolate 25 26 // Write the rest of the program here. Chocolate 27 return O; 28 }// End of main() Cinnamon 29 Vanilla !!
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT