Hey guys,
I am writing a program with functions that does different things for a user. This is a program i am writing for school and my lab teachers are horrible at helping us. The problem is that i get an illegal case error for all my cases (five cases). CAn anyone please help?
#include <iostream>
#include <cmath>
using namespace std;
int userChoice,choiceCount (0);
int displayMenu ();
//displays menu
void drawTriangle();
// draws an inverted triangle
void sumOfNumbers();
// takes 2 numbers and averages them and gives min and max
void sumOfNumbersSentinel();
//takes numbers gives averages and min and max
void powerOfNumbers();
//takes base and raises it to the power
void quitProgram ();
//quits program
// prompts the user
int main ()
{
cout << "Welcome to the my program\n"
<< "I can do several things for you.\n"
<< "When you are ready to enter my program,\n"
<< "Hit any key\n"
<< endl;
system("pause");
system("cls");
//Gives the user choices and asks for a choice
do
{
cout << "Please choose from:\n"
<< "1. draw an inverted triangle of your chosen height using your chosen letter\n"
<< "2. enter some numbers and learn the sum, average, min and max of your inputs\n"
<< "3. same 2. but with a different way to end inputting\n"
<< "4. let me calculate a^b (a raised to the b) for whatever a and b you'd like\n"
<< "5. quit this program\n"
<< endl ;
cin >> userChoice;
if ((userChoice>5||userChoice<1))
cout << "Not a valid choice try again: " << endl ;
cin >> userChoice ;
system("pause");
system("cls");
//Switch for user choice
switch (userChoice);
{
case 1:
drawTriangle ();
break;
case 2:
sumOfNumbers();
break;
case 3:
sumOfNumbersSentinel();
break;
case 4:
powerOfNumbers();
break;
case 5:
cout << "End of program" << endl;
cout << "You have made "
<< choiceCount
<< " choice(s)"
<<endl;
break;
}
}while ((userChoice<=4||userChoice>=1)) ;// braces for do
}//main brace
void drawTriangle ()
{
char letterChoice ;
int length ;
cout << "What letter do you want to use for your triangle?: " << endl;
cin >> letterChoice;
cout << " What is your desired length: " << endl;
cin >> length;
for( int outer=length; outer > 0; outer--)
{
for(int inner=0; inner<outer; inner ++)
{
cout << letterChoice ;
}
cout << endl;
choiceCount++ ;
}
}
void sumOfNumbers( )
{
int num1, num2 ;
double average ;
cout << "Please enter your first number: " << endl;
cin >> num1;
cout << "Please enter your second number: " << endl;
cin >> num2;
average = (num1+num2)/2;
cout <<" The average of your two numbers is: "
<< average
<<endl ;
if(num1>num2)
cout << "The max number is "
<<num1
<< " and the minimum is"
<<num2
<<endl ;
else if (num2>num1)
cout << "The max number is "
<<num2
<< " and the minimum is"
<<num1
<<endl;
choiceCount++ ;
}
void sumOfNumbersSentinel()
{
const int stopValue (-999);
int num1, num2,sum,numCount(0), numberCounter,numbers,max,min;
double average;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision (2);
while (numbers!=stopValue)
cout << "Please enter the numbers you wish to average(enters -999 to end input): "<< endl ;
cin >> numbers;
sum+=numbers ;
numCount++ ;
if (numbers==stopValue)
cout << "Processing numbers..." << endl;
average=sum/numCount ;
cout << "The average of your numbers are "
<<average
<< endl;
if(num1<num2)
min=num1 ;
else if (num1>max)
max=num1 ;
cout << "The max number is "
<<max
<< " and the minimum is"
<<min
<<endl;
choiceCount++ ;
}
void powerOfNumbers ()
{
double base, exponent,result ;
cout << "What will your base number be?; " << endl;
cin >> base;
cout << "What will your exponent be?: " << endl;
cin >> exponent;
result=pow(base,exponent) ;
cout << "Your final number is "
<< result
<< endl;
}