I'm getting this error and have no clue how to solve it it's probably one of my curly braces but can't pinpoint it Error main function must return a value
Header
#include <iostream>
using namespace std;
void start (void);
long factorial(int number);
void toH(int n, char source, char a, char dest);
int summation(int number);
Lab1.cpp
#include <iostream>
#include "Lab1.h"
long factorial(int number) {
if (number >= 1)
return number * factorial(number - 1);
else
return 1;
}
void toH(int n, char start, char a, char dest) {
if (n == 1) {
cout << "Move Disk " << n << " from " << start << " to " << dest << endl;
return;
}
toH(n - 1, start, dest, a);
cout << "Move Disk " << n << " " << start << " to " << dest << endl;
toH(n - 1, a, start, dest);
}
int summation(int number) {
if (number != 0)
return number + summation(number - 1);
else
return number;
}
Main
#include "Lab1.h"
int main() {
start(); {
}
int n;
int ch;
char yn;
// prints to user
cout << "1. Recursive factorial" << endl;
cout << "2. Tower of Hanoi" << endl;
cout << "3. Recursive Summation" << endl;
cout << "0. Exit" << endl;
cout << endl << "Enter choice: ";
//recieeves user input
cin >> ch;
// forces user to enter a numeric number
if (!cin) {
cout << "Invalid input\n";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
if (ch == 0) {
cout << endl << endl << "You chose to exit\n";
// system("pause");
exit(0);
}
else if (ch == 1) {
cout << endl << "Enter a number to find factorial: ";
cin >> n;
//calling long fact in header
long fact = factorial(n);
cout << endl << "Factorial of " << n << " is: " << fact << endl << endl;
cout << "would you like to go again Y or N ";
cin >> yn;
}
else if (ch == 2) {
// sets up for user input
cout << "Enter number of disks: ";
cin >> n;
toH(n, 'A', 'B', 'C');
cout << endl << endl;
cout << "would you like to go again Y or N ";
cin >> yn;
}
else if (ch == 3) {
// sets up for user input
cout << endl << "Please enter a number to find Recursive summation: ";
cin >> n;
//calling sum in header
int sum = summation(n);
cout << endl << "Sum is: " << sum << endl << endl;
@Fundoram,
You will get more attention if you put code in code tags - your sample is almost indecipherable. We can't refer to line numbers, we can't see the structure because the indentation is absent and we can't try it in c++ shell. You may want to break it down into separate files later, but for the purposes of posting in the forum it is better as one unit, so that we can run it in c++ shell and don't have to download lots of separate files.
For your particular noted exception it comes from here: elsereturn;
on line number ... goodness knows.
It is the exit from int main(), so if you want it then return an int; e.g. elsereturn 0;
Also, as far as I can see, you haven't defined a routine start(); and a line like start;
without function brackets isn't going to do anything.
Unless your implementation has a lot of nesting of includes then you will need to include the appropriate header for numeric_limits explicitly.