Proofread my Code!

Ignore the fact that my functions are rather incomplete. I really have a question about whether or not i can declare variables in the function when i declare it.


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

void area_triangle ();
void area_square();
void area_rectangle();
void menu();

int main()
{

cout<< “Welcome to area finder.” << endl;
menu();

return0;
}

Do
void menu()
{
char choice;

cout<< “Please select T)riangle, S)quare, R)ectangle, Q)uit”<<endl;
cin >> choice;

if (choice == ‘T’)
area_triangle();
else if(choice==’S’)
area_square();
else if(choice==’R’)
area_rectangle();
else if (choice == ‘Q’)
cout << “You have decided to quit. Have a nice day!” << endl;
else
{
cout << “You have not elected a valid choice” << endl;
}
while (choice != ‘Q’)
}

void area triangle(float base, height, traingle_area)
{
cout << triangle_area << endl;
void menu();
}


void area_square (float side, square_area)
{
cout << square_area << endl;
void menu();
}


void area_rectangle(rectangle_area, length, width)
{
cout << rectangle_area << endl;
void menu();
}
closed account (zvRX92yv)
WHY U NO USE CODE TAGS?!?

[code] [/code]

And I'm certain that you can't do statements outside of functions..
Last edited on
using switch statement will make it more readable .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream.h>
#include <iomanip.h>
#include <math.h>

void area_triangle ();
void area_square();
void area_rectangle();
void menu();

int main()
{
		char choice ; 
		cout<< “Welcome to area finder.” << endl;
		menu(&choice);
		return0;
}


void menu(char* choice)
{


		cout<< “Please select T)riangle, S)quare, R)ectangle, Q)uit”<<endl;
		cin >> choice;
		do{
				switch( choice ) 
				{
					case  ‘T’:
						area_triangle();
						break;
					case ’S’:
						area_square(); 
						break;
					case ’R’:
						area_rectangle();
						break;
					case ‘Q’:
						cout << “You have decided to quit. Have a nice day!” << endl;
						break;
					default:
						cout << “You have not elected a valid choice” << endl;
						cout<<"Do you want to enter again \n";
				}
		}while (choice != ‘Q’)
}

void area triangle(float base, height, traingle_area)
{
		cout << triangle_area << endl;
}


void area_square (float side, square_area)
{
		cout << square_area << endl;
}


void area_rectangle(rectangle_area, length, width)
{
cout << rectangle_area << endl;

}

You can declare a variable wherever you want. Passing 'choice' to menu() is unnecessary. Declare 'choice' before it used as a char not char *

For a function each and every parameter variable needs a type (not only the first). This void area_square (float side, square_area) is wrong, must be void area_square (float side, float /*?*/ square_area)

This void area_square(); and this void area_square (float side, /*missing type here*/ square_area) are different function due to the parameter. The linker will complain that area_square() cannot be found.

The compile accepts only '' and "" as quotation marks. No fancy quotation marks are allowed.

1
2
3
4
5
void area_rectangle(rectangle_area, length, width)
{
cout << rectangle_area << endl;
void menu(); // This doesn't call menu()! It's a declaration, remove void
}
Topic archived. No new replies allowed.