Calling a Function

Why won't this work?
1
2
3
case 2:
				int grades();
				break;

and when i initialize the function it wont work
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
int grades()
{
	vector<int> teachernumber;
	vector<int> studentnumber;
	vector<int> classnumber;
	string schoolname="";
	cout << "This part of the program will average your grades." << endl;
	cout << "Please select the thing you would like to fill out." << endl;
	cout << "[1]Schoolname" << endl;
	cout << "[2]Teacher Info" << endl;
	cout << "[3]Classes" << endl;
	cout << "[4]Students" << endl;
	cout << "[5]Grades" << endl;
	int menu;
	cin >> menu;
	while (menu != 1 && menu != 2 && menu != 3 && menu != 4 && menu != 5)
	{
		cout << "Invalid input" << endl;
		cin >> menu;
	}
	switch (menu)
	{
	case 1:
		cout << "Fill out the school name." << endl;
		cin >> schoolname;
		break;
	case 2:
		cout << "How many teachers are there?" << endl;
		cout << "What is the name of teacher #" << "?" << endl;
		break;
	case 3:
		cout << "How many classes do you have "<< "?" << endl;
		cout << "What is the name of class #" << "?" << endl;
		break;
	case 4:
		cout << "How many students are in " << "?" << endl;
		cout << "What is the name of student #" << "?" << endl;
		break;
	case 5:
		cout << "What are the grades?" << endl;
	}
	return 2182;
}

the program i know wont actually do anything useful but i want to get it so itll at least call it right
wait whats your question? I dont even see int grades in case 2.. unless im missing something
when i write 2( thus the case 2;) it just displays the main menu again not the actual function
oh sorry i see int grades now but whats your question?
it wont do the function it wont display the words i have a menu on a loop and it'll just show that menu again instead of doing what i want
you want full source code?
Yah if you could that would be great.
int grades(); is a forward declaration for a function, named grades, that takes no parameters and returns an integer.

int grades; is the declaration and definition of an uninitialized integer variable.

grades(); invokes a function named grades that takes no parameters, similar to the one posted above.

Hope this helps.
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string note="";
int grades();
int calculator();
int notes();
int menu= 0;
int main()
{
	system("color C8");

	while (menu == 1||menu == 2||menu == 3||menu == 0)
	{
		cout << "Welcome to TeacherHelp" << endl;
		cout << "This Program will do many things to help teachers." << endl;
		cout << "Write the number of your choice." << endl;
		cout << "[1]Calculator" << endl;
		cout << "[2]Average Grades" << endl;
		cout << "[3]Note" << endl;
		cout << note << endl;
		cin >> menu;
		std::cin.ignore();
			switch(menu)
			{
			case 1:
				int calculator();
				break;
			case 2:
				int grades();
				break;
			case 3:
				notes();
				break;
			default:
				cout << "Invalid Input" << endl;
				cin >> menu;
			}
		}
	return 2182;
}
int notes()
{
	cout << "Create a note" << endl;
	std::getline(std::cin, note);
	return 2182;
}
int grades()
{
	string schoolname="";
	cout << "This part of the program will average your grades." << endl;
	cout << "Please select the thing you would like to fill out." << endl;
	cout << "[1]Schoolname" << endl;
	cout << "[2]Teacher Info" << endl;
	cout << "[3]Classes" << endl;
	cout << "[4]Students" << endl;
	cout << "[5]Grades" << endl;
	int menu;
	cin >> menu;
	switch (menu)
	{
	case 1:
		cout << "Fill out the school name." << endl;
		cin >> schoolname;
		break;
	case 2:
		cout << "How many teachers are there?" << endl;
		cout << "What is the name of teacher #" << "?" << endl;
		break;
	case 3:
		cout << "How many classes do you have "<< "?" << endl;
		cout << "What is the name of class #" << "?" << endl;
		break;
	case 4:
		cout << "How many students are in " << "?" << endl;
		cout << "What is the name of student #" << "?" << endl;
		break;
	case 5:
		cout << "What are the grades?" << endl;
		break;
	default:
		cout << "Invalid Input" << endl;
		cin >> menu;
		break;
	}
	return 2182;
}
moorecm
then what do i do?
i see thanks everyone take out the int before grades();
And before calculator(); on line 29. It also looks like you're going to hit the mixing cin and getline problem in the near future.
Last edited on
yeah already got that and fixed it
Topic archived. No new replies allowed.