First multiple function program not working.

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
Disch wrote:
Protip: When code doesn't compile, the compiler error tells you the reason why.

Protip 2: When asking about compiler errors, saying "my code won't compile" does not help us. Instead, post the error you get.


And use [code][/code] tags, please.
Lotsa errors... :D

Line 0: Please use code tags in the future. :)
http://cplusplus.com/articles/firedraco1/

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.

Line 13: Similarly, this needs to be return 0;

Line 51: Careful...

Lines 92 and 96: Your if and else syntaxes are way off. :/
http://cplusplus.com/doc/tutorial/control/#if

Lines 92 and 96: << and >> are normally bit shift operators. I don't think this is what you meant.

Line 127: You probably meant something else.
http://www.cplusplus.com/reference/clibrary/cmath/sqrt/

Good luck!

-Albatross
Last edited on
Topic archived. No new replies allowed.