# [SOLVED] Noob C++ Question



## sirusx69 (Oct 13, 2007)

ok first off this assignment is for college where i'm taking a C++ Class.
I'm not asking for anyone to "do" my assignment, it is already done but I'm getting a error message when I try to compile using G++.


```
[[email protected] School]$ g++ Chapter_4.cpp 
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
```
Here is the actual C++ code


```
/*Written by Trey Cube
March 26, 2010	
Chapter 4
Assignment 1, Software Sales*/

#include <iostream>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int runcalc();
int math();


int main()
{
	int selection;
		system("clear");
		cout << "\n" << "\n";
		cout << "Cubert Software Inc. Sales Calculator";
		cout << "*************************************";
		cout << "Main Menu: \n"
		cout << "\n";	
		cout << "1. Run Calculation Program\n";
		cout << "2. Instructions\n";
		cout << "3. More Information\n";
		cout << "4. Exit\n":
		cout << "*************************************";
		cout << "Select an option: ";
		cin  >> selection;

	switch(selection)
	{
		case 1: 
			system("clear");
			runcalc();
		case 2:
			system("clear");
			cout << "1. Calculation Program: \n" << "\n";
			cout << "   This program is to calculate the users total price based on how many ";
			cout << "   units the user has purchased.";
			cout << "\n" << "\n";
			cout << "Press enter to continue. . .";
			cin.get();
			system("clear");
			main();
		case 3:
			system("clear");
			cout << "This program was made by our software specialist team ";
			cout << "to better assist users with purchases from Cubert Software";
			cout << "\n" << "\n";
			cout << "Press enter to continue. . .";
			cin.get();
			system("clear");
			main();
		case 4:
			system("clear");
			cout << "Thank you for using our software! \n";
			cout << "******************************\n";
			cout << "Cubert Software Inc.\n";
			cout << "******************************\n";
			sleep(5); 
			system("clear");
	}	
}

int runcalc()
{
int units;
double discount, price;
	cout << "***************************************\n";
	cout << " Cubert Software Inc. Sales Calculator\n";
	cout << "***************************************\n" << "\n";
	cout << "q - return to main menu\n" << "\n";	
	cout << "How many units purchased: \n";
	cin >> units
	
	if(1 < units < 9)
		{
			math();
			cout << "You have purchased " << units << ".\n";
			cout << "Your price: $" << setprecision(2) << price << "\n" << "\n";
			runcalc();
		}
	else if(10 < units < 19)
		{
			discount = .2;
			math();
			cout << "You have purchased " << units << ".\n";
			cout << "Your price: $" << setprecision(2) << price << "\n" << "\n";
			cout << "You qualified for a 20% Discount!\n" << "\n";
			runcalc();
		}
	else if(20 < units < 49)
		{
			discount = .3;
			math();
			cout << "You have purchased " << units << ".\n";
			cout << "Your price: $" << setprecision(2) << price << "\n" << "\n";
			cout << "You qualified for a 30% Discount!\n" << "\n";
			runcalc();
		}
	else if(50 < units < 99)
		{
			discount = .4;
			math();
			cout << "You have purchased " << units << ".\n";
			cout << "Your price: $" << setprecision(2) << price << "\n" << "\n";
			cout << "You qualified for a 40% Discount!\n" << "\n";
			runcalc();	
		}
		
	else if(units >= 100)
		{
			discount = .5;
			math();
			cout << "You have purchased " << units << ".\n";
			cout << "Your price: $" << setprecision(2) << price << "\n" << "\n";
			cout << "You qualified for a 50% Discount!\n" << "\n";
			runcalc();
		}
	else if(units < 1)
		{
			cout << "That is a invalid number, please enter a minimum value of 1";
			cout << "\n" << "\n" << "\n";
			runcalc();
		}
}

int math()
{
	percent = (units * 99) * discount;
	price = (units * 99) - percent;
}
```
From the google results the error means that my Main() function is not defined or, not even there for that matter. Which we can all see from the code that I did infact have a main() function in there.

If i'm wrong please tell me, this is only my 4th day with C++ (I love programming though!)

Thanks 

Trey


----------



## icebelowzero (Jun 22, 2009)

*Re: Noob C++ Question*

I'm an autodidact. So I'm teaching myself programming as well from online tutorials, my own kind of prerequisite to classes. 
I currently use code::blocks which is free and it's telling me it has many errors. Below you will find them. I did find a remedy to some though. 
In "int selection;"
1. cout << "Main Menu: \n" (you forgot the semi-colon)
2. cout << "4. Exit\n": (Not sure if you ment a semi-colon, but adding one cleared that error log.)

switch(selection)
Case 4
On line 63
The variable "sleep" was not declared. I'm just a beginner so I'm not sure myself how to have it declared.

int runcalc()
Line 77
cin >> units (missing semi-colon)

Now we are on the very last of your code.

}

int math()
{
percent = (units * 99) * discount;
price = (units * 99) - percent;
}

The error presented was that units was not defined. I did noticed however, if you move the "}" above int math() to being the last part of the code, the "units" will be defined under the rest of the code above it.

Next you just have to define percent and price. Unless I'm missing something myself, again I'm new myself and haven't taken the luxury of a class yet.







```
-------------- Build: Debug in Practice ---------------

Compiling: main.cpp
C:\Users\Pepsi\8bits\Practice\main.cpp: In function `int main()':
C:\Users\Pepsi\8bits\Practice\main.cpp:24: error: expected `;' before "cout"
C:\Users\Pepsi\8bits\Practice\main.cpp:28: error: expected `;' before ':' token
C:\Users\Pepsi\8bits\Practice\main.cpp:63: error: `sleep' was not declared in this scope
C:\Users\Pepsi\8bits\Practice\main.cpp:63: warning: unused variable 'sleep'
C:\Users\Pepsi\8bits\Practice\main.cpp: In function `int runcalc()':
C:\Users\Pepsi\8bits\Practice\main.cpp:79: error: expected `;' before "if"
C:\Users\Pepsi\8bits\Practice\main.cpp:86: error: expected primary-expression before "else"
C:\Users\Pepsi\8bits\Practice\main.cpp:86: error: expected `;' before "else"
C:\Users\Pepsi\8bits\Practice\main.cpp:95: error: expected primary-expression before "else"
C:\Users\Pepsi\8bits\Practice\main.cpp:95: error: expected `;' before "else"
C:\Users\Pepsi\8bits\Practice\main.cpp:104: error: expected primary-expression before "else"
C:\Users\Pepsi\8bits\Practice\main.cpp:104: error: expected `;' before "else"
C:\Users\Pepsi\8bits\Practice\main.cpp:114: error: expected primary-expression before "else"
C:\Users\Pepsi\8bits\Practice\main.cpp:114: error: expected `;' before "else"
C:\Users\Pepsi\8bits\Practice\main.cpp:123: error: expected primary-expression before "else"
C:\Users\Pepsi\8bits\Practice\main.cpp:123: error: expected `;' before "else"
C:\Users\Pepsi\8bits\Practice\main.cpp:71: warning: unused variable 'discount'
C:\Users\Pepsi\8bits\Practice\main.cpp:71: warning: unused variable 'price'
C:\Users\Pepsi\8bits\Practice\main.cpp: In function `int math()':
C:\Users\Pepsi\8bits\Practice\main.cpp:133: error: `percent' was not declared in this scope
C:\Users\Pepsi\8bits\Practice\main.cpp:133: error: `units' was not declared in this scope
C:\Users\Pepsi\8bits\Practice\main.cpp:133: error: `discount' was not declared in this scope
C:\Users\Pepsi\8bits\Practice\main.cpp:134: error: `price' was not declared in this scope
C:\Users\Pepsi\8bits\Practice\main.cpp:133: warning: unused variable 'discount'
C:\Users\Pepsi\8bits\Practice\main.cpp:134: warning: unused variable 'price'
Process terminated with status 1 (0 minutes, 0 seconds)
18 errors, 5 warnings
```


----------



## sirusx69 (Oct 13, 2007)

*Re: Noob C++ Question*

Lol i fixed those issues. I also found out i was compiling the wrong cpp file =)


----------

