I have been assigned to write a program that has 5 functions ( main, menu, exponetial, factorial, and pthagorean therom) and does the functions. The code i have written will not compile and I can't figure out why. Any help would be great. Thanks.
Here's the code:
#include <iostream>
using namespace std; // so we dont have to use std anymore
void menu (); // menu function
void exponent (); // exponent function
void factorial (); // factorial function
void pythag (); // pythagorean therom function
void main () // program begins
{
menu (); // call menu function
return; // end program
}
void menu () // menu function
{
int choice; // user's choice
char quit; // user's quit option
int swit = 1;
do // do loop
{
cout << "Welcome to my menu\n"; // welcome screen
cout << "choose one of the following options\n"; // give the user options
cout << "for exponential choose 1\n"; // user's first option
cout << "for factorial choose 2\n"; // user's second option
cout << "for pyhagorean therom choose 3\n"; // user's third option
cout << "anything else will result in an error\n"; // warning user of error
switch (swit) // start switch
{
case '1' : (choice = 1); // option 1
exponent (); // calling exponential function
case '2' : (choice = 2); // option 2
factorial (); // calling factorial function
case '3': (choice = 3); // option 3
pythag (); // calling pyhagorean therom function
}
if (choice != ((1)||(2)||(3))); cout << "Error"; // error message if choice isn't 1,2, or 3
cout << "would you like to quit? (y/n)\n"; // quit option
cin >> quit; // user's quit answer
} while (quit = 'n'); // do loop when quit is not yes
}// end function
void exponent () // exponent function
{
double num; // base number
int exp; // exponent number
double sum; // answer
cout<< "Welcome to the exponential portion of my program\n"; // welcome screen
cout << "enter your base number\n"; // user enters base number
cin >> num; // user's base number
cout << "enter your exponent"; // user enters exponent
cin >> exp; // user's exponent
do // do loop
{
sum = num*num;
exp --; // decrease exp by one
} while (exp != 0); // end do loop
cout << "your answer is" << sum; // answer displayed to user
} // end function
void factorial () // factorial function
{
int n;
int newn;
cout << "welcome to the factorial portion of my program\n"; // welcome screen
cout << " factorial is defined as n != 1x2x3x4...\n"; // defining factorial
cout << "enter your n\n"; // promt for user's n
cin >> n; // input user's n
do // do loop
{
if n >> 0; // n is greater than 0
newn = n--; // decrease n by one
n = n*newn;
else n << 0; // n is less than 0
newn = n++; // increase n by one
n = n * newn;
} while (n != 0); // end loop
}//end function
void pythag () // pythagorean therom function
{
int a;
int b;
int c;
cout << " welcome to the pythagorean therom of my program\n"; // welcome screen
cout << " pythagorean therom is defined as a squared + b squared = c squared\n"; // define pythagorean therom
cout << "enter a\n"; // promt user for a
cin >> a; // input user's a
a = a*a; // a squared
cout << "enter b\n"; // promt user for b
cin >> b; // input user's b
b = b*b; // b squared
c = a+b; // calculate c squared
c = sqr(c); // squareroot c
cout << " C= " << c; // oput user's answer
}// end function
Line 10: Any fully standards-compliant compiler will refuse to compile with this line in place. It has to be int main(), or one of the other accepted forms of main.