I am trying to find a way to use an array inside my mixed color program where the user enters two prime colors to give the mixed color as the result. I do not know how to turn 'red', 'blue', and 'yellow' into and array to then ask user to enter a 0,1, or 2 for the array to use red, blue, or yellow. Can I get some help on how to use this array? #include #include using namespace std; int main(){ string arr[] = {red, blue, yellow}; string color1, color2; string mixedColor; char choice; do { cout <<"Enter first prime color '0' for red, '1' for blue, and '2' for yellow: " <>color1; cout <<"Enter different second prime color, '0' for red, '1' for blue, and '2' for yellow: " <>color2; if ((color1 == 0 && color2 == 1) || (color1 == 1 && color2 == 0)){ mixedColor = "purple"; }else if ((color1 == 0 && color2 == 2) || (color1 == 2 && color2 == 0)){ mixedColor = "orange"; }else if ((color1 == 1 && color2 == 2) || (color1 == 2 && color2 == 1)){ mixedColor = "green"; }else{ mixedColor = "unknown"; } // Display results cout<<"Mixed color for your selection is"<>choice; while (toupper(choice)=='Y';) cout<<"Goodbye!"<
I am trying to find a way to use an array inside my mixed color program where the user enters two prime colors to give the mixed color as the result. I do not know how to turn 'red', 'blue', and 'yellow' into and array to then ask user to enter a 0,1, or 2 for the array to use red, blue, or yellow. Can I get some help on how to use this array? #include #include using namespace std; int main(){ string arr[] = {red, blue, yellow}; string color1, color2; string mixedColor; char choice; do { cout <<"Enter first prime color '0' for red, '1' for blue, and '2' for yellow: " <>color1; cout <<"Enter different second prime color, '0' for red, '1' for blue, and '2' for yellow: " <>color2; if ((color1 == 0 && color2 == 1) || (color1 == 1 && color2 == 0)){ mixedColor = "purple"; }else if ((color1 == 0 && color2 == 2) || (color1 == 2 && color2 == 0)){ mixedColor = "orange"; }else if ((color1 == 1 && color2 == 2) || (color1 == 2 && color2 == 1)){ mixedColor = "green"; }else{ mixedColor = "unknown"; } // Display results cout<<"Mixed color for your selection is"<>choice; while (toupper(choice)=='Y';) cout<<"Goodbye!"<
Chapter6: Using Arrays
Section: Chapter Questions
Problem 6E
Related questions
Question
I am trying to find a way to use an array inside my mixed color program where the user enters two prime colors to give the mixed color as the result. I do not know how to turn 'red', 'blue', and 'yellow' into and array to then ask user to enter a 0,1, or 2 for the array to use red, blue, or yellow. Can I get some help on how to use this array?
#include <iostream>
#include <string>
using namespace std;
int main(){
string arr[] = {red, blue, yellow};
string color1, color2;
string mixedColor;
char choice;
do {
cout <<"Enter first prime color '0' for red, '1' for blue, and '2' for yellow: " <<endl;
cin >>color1;
cout <<"Enter different second prime color, '0' for red, '1' for blue, and '2' for yellow: " <<endl;
cin >>color2;
if ((color1 == 0 && color2 == 1) || (color1 == 1 && color2 == 0)){
mixedColor = "purple";
}else if ((color1 == 0 && color2 == 2) || (color1 == 2 && color2 == 0)){
mixedColor = "orange";
}else if ((color1 == 1 && color2 == 2) || (color1 == 2 && color2 == 1)){
mixedColor = "green";
}else{
mixedColor = "unknown";
}
// Display results
cout<<"Mixed color for your selection is"<<color1<<"and"<<color2<<"is"<<mixedColor<<endl;
// Continue or exit?
cout<<"Would you like to mix again?(Y/N): ";
cin>>choice;
while (toupper(choice)=='Y';)
cout<<"Goodbye!"<<endl;
}
return 0;
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 2 images
Knowledge Booster
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.Recommended textbooks for you
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning