Question

In: Computer Science

Write a program that does the following things: in C++ 1 ) ask the user for...

Write a program that does the following things: in C++

1 ) ask the user for 2 primary colors (red, blue, yellow) [should be in main]

2 ) determine the secondary color the 2 primarily colors make [should be in newColor function]

red + blue = purple

red + yellow = orange

blue + yellow = green

3 ) Print the following message

<color1> and <color2> makes <color3>


Solutions

Expert Solution

The Program in C++ for mixing of two primary colors to make third is as follows:

Comments are also included for better understanding.

#include <iostream>
using namespace std;

int main()
{
    // Variables
    string color_1, color_2;

    // Ask user for 2 primary colors
    cout << endl;
    cout << "Enter 1st primary color : ";
    cin >> color_1;
    cout << "The 2nd primary color is: ";
    cin >> color_2;

    // Format line break
    cout << endl;

    // Error checking, calculation, & Display.
    // Eliminating confusion between upper case and lower case.
    // define the result for mixer of two primary colors.
    if (color_1 == "red" || color_1 == "Red" || coior_1 == "RED")
    {
        if (color_2 == "blue" || color_2 == "Blue" || color_2 == "BLUE")
        {
            cout << color_1 << " and ";
            cout << color_2 << " makes purple.\n";
        }
        else if (color_2 == "yellow"  || color_2 == "Yellow" || color_2 == "YELLOW")
        {
            cout << color_1 << " and ";
            cout << color_2 << " makes Orange.\n";
        }
    }
    else if (color_1 == "blue" || color_1 == "Blue" || color_1 == "BLUE")
    {
        if (color_2 == "red" || color_2 == "Red" || color_2 == "RED")
        {
            cout << color_1 << " and ";
            cout << color_2 << " makes purple.\n";
        }
        else if (color_2 == "yellow" || color_2 == "Yellow" || color_2 == "YELLOW")
        {
            cout << color_1 << " and ";
            cout << color_2 << " makes green.\n";
        }
    }
    else if (color_1 == "yellow" || color_1 == "Yellow" || color_2 == "YELLOW")
    {
        if (color_2 == "red" || color_2 == "Red" || color_2 == "RED")
        {
            cout << color_1 << " and ";
            cout << color_2 << " makes orange.\n";
        }
        else if (color_2 == "blue" || color_2 == "Blue" || color_2 == "BLUE")
        {
            cout << color_1 << " and ";
            cout << color_2 << " makes green.\n";
        }
    }
    else
    {
        cout << "Neither " << color_1;
        cout << " nor " << color_2;
        cout << " is a prime color. ";
        cout << "\nRun the program and try again.\n";
        cout << "Remember a primary color is either Red,";
        cout << "Blue, or Yellow.\n";
    }

    // Formatting
    cout << endl << endl;

    // Terminate program
    return 0;
}

Related Solutions

Write a program that does the following. It will ask the user to enter an integer...
Write a program that does the following. It will ask the user to enter an integer larger than 1, and the if entered integer is not larger than 1, it keeps prompting the user. After the user enters a valid integer, the program prints all the prime factors of the integer (including the repeated factors). For example, if the entered integer is 24, the program prints: 2 2 2 3 Run your program with the test cases where the entered...
Write a program that does the following in order: 1. Ask user to enter a name...
Write a program that does the following in order: 1. Ask user to enter a name 2. Ask the user to enter five numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 3. Calculate the sum of the numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 4. If the sum is greater than 0, print out the sum 5. If the sum is equal to zero, print out “Your account balance is zero” 6. If the sum is less than 0, print out “Your account...
Implement a program in C++ that does the following: Ask the user and read at least...
Implement a program in C++ that does the following: Ask the user and read at least 10 numbers as input from the keyboard and stores them in a an array Displays the array of numbers on the screen (as is, before sorting) Sorts those numbers in the array using Selection Sort Algorithm Displays the array of numbers on the screen (AFTER sorting)
In C: Write a complete program that performs the following task: Ask the user for the...
In C: Write a complete program that performs the following task: Ask the user for the number of sequences to display. For each sequence, Ask the user for a starting value Print out the value and double it (multiply by 2). Continue printing and doubling (all on the same line, separated by one space each) as long as the current number is less than 1000, or until 8 numbers have been printed on the line. You may assume that the...
Using Python write a program that does the following in order: 1. Ask user to enter...
Using Python write a program that does the following in order: 1. Ask user to enter a name 2. Ask the user to enter five numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 3. Calculate the sum of the numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 4. If the sum is greater than 0, print out the sum 5. If the sum is equal to zero, print out “Your account balance is zero” 6. If the sum is less than 0, print out...
Program specifics: Write a C++ program that does the following: a. Asks the user for the...
Program specifics: Write a C++ program that does the following: a. Asks the user for the distance to the pin and the depth of the green (both in yards). (Note: The pin is the hole in the green and the depth is the diameter of the green, assuming it is circular.) b. Asks the user for an integer club number from 2 to 10, where 10 is the pitching wedge (this club lifts the ball out of rough, sand, etc)....
Write a C program that does the following: 1) Asks the user to enter an integer...
Write a C program that does the following: 1) Asks the user to enter an integer N 2) Asks the user to enter three words with at least N letters and at most 20 letters 3) Prints the first N letters from the first word 4) Prints the last N letters from the second word 5) Prints all letters in the odd position in the third word Output: Please enter an integer N: 3 Please enter a word with at...
Please code in c# (C-Sharp) Write a program that will ask the user for their name....
Please code in c# (C-Sharp) Write a program that will ask the user for their name. If the user does not input anything, display a warning before continuing. The program will then ask the user whether they want to have an addition, subtraction, multiplication, or division problem. Once the user indicates their choice, the program will display 2 randomly generated numbers from 1 to 9 in a math problem matching the user’s choice. Example: user selects addition, the equation presented...
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
Ask the user to input a series of numbers, write a C# program to output the...
Ask the user to input a series of numbers, write a C# program to output the sum, max, and min. Be sure to do error checking if the user input is not a number.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT