F
Fao
Hi, I am in my first year of C++ in college and my professor wants me
to Write a Program with multiple functions,to input two sets of
user-defined data types:
One type named 'Sign' declared by "typedef" to contain only
either +10 or -10 and
the other type named Color declared by "enum" to contain only
black, blue, purple, red, white, and yellow.
For each set of inputs, output their sum, average,
maximum and second largest.
I must also use typedef and enum for two data types.
I do not have a problem with finding the sum, max, avg, second largest,
my problem is how to properly use "typedef" and "enum".
Here is what I have, which is completely wrong(laugh if you want):
#include <iostream>
using namespace std;
enum Color {black, blue, purple, red, white, yellow};
void PrintEnum();
int main();
{
cout << "Enter the First two letters of your favorite color: " << endl;
cin >> ch1 >> ch2;
switch (ch1)
{
case 'a': if (ch2 == '1')
Color = black;
else
Color = red;
break;
case 'b': Color = blue;
break;
case 'c': if (ch2 == 'w')
Color = white;
else
Color = yellow;
break;
case 'd': Color = purple
break;
default: cout << "Illegal input." << endl;
return Colors;
}
void PrintEnum(Favorite Colors)
{
switch (Colors)
{
case black: cout << "black";
break;
case blue: cout << "blue";
break;
case purple: cout << "purple";
break;
case red: cout << "red";
break;
case white: cout << "white";
break;
case yellow: cout << "yellow";
break;
}
}
If anyone, and I mean anyone out there can help me, it would be greatly
appreciated.
to Write a Program with multiple functions,to input two sets of
user-defined data types:
One type named 'Sign' declared by "typedef" to contain only
either +10 or -10 and
the other type named Color declared by "enum" to contain only
black, blue, purple, red, white, and yellow.
For each set of inputs, output their sum, average,
maximum and second largest.
I must also use typedef and enum for two data types.
I do not have a problem with finding the sum, max, avg, second largest,
my problem is how to properly use "typedef" and "enum".
Here is what I have, which is completely wrong(laugh if you want):
#include <iostream>
using namespace std;
enum Color {black, blue, purple, red, white, yellow};
void PrintEnum();
int main();
{
cout << "Enter the First two letters of your favorite color: " << endl;
cin >> ch1 >> ch2;
switch (ch1)
{
case 'a': if (ch2 == '1')
Color = black;
else
Color = red;
break;
case 'b': Color = blue;
break;
case 'c': if (ch2 == 'w')
Color = white;
else
Color = yellow;
break;
case 'd': Color = purple
break;
default: cout << "Illegal input." << endl;
return Colors;
}
void PrintEnum(Favorite Colors)
{
switch (Colors)
{
case black: cout << "black";
break;
case blue: cout << "blue";
break;
case purple: cout << "purple";
break;
case red: cout << "red";
break;
case white: cout << "white";
break;
case yellow: cout << "yellow";
break;
}
}
If anyone, and I mean anyone out there can help me, it would be greatly
appreciated.