Trouble remaking a project with void functions

I'm still a little iffy on how to use functions separate from main but this is what i've got so far

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
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

void gradeloopFunction() //gets name saves it into a file then takes grades grade input and averages them
{
	 for (int i = 1; i <= number_of_Students; i++)
        {
  cout << "Enter a name for student #" << i << " ";
  getline (cin, name);
  cin.ignore();
  outputFile << name << endl;
  //write the name to the text file
 
        int number_of_Grades = 3;
	 for (int j = 1; j <= number_of_Grades; j++) 
  {
   cout << "Enter a grade #" << j << " ";
   cin >> grade;

     while (grade > 100 || grade < 1)
	   {
		   cout << "Invalid: Please enter a number between 1 & 100!" << endl;
		   cin >> grade;
	   }
   //add the grade to the average
	   cout << setprecision(1) << fixed;
	   average = average + grade;
	   average = average / 3;
	   return average;
  }

	 void averageloopFunction()//turns grade into a char 
	 {
		 char grd;
		 if(average >= 90)
		 {
			 grd = 'A';
		 }
		 if(average >= 80; average < 90)
		 {
			 grd = 'B';
		 }
		 if(average >= 70; average < 80)
		 {
			 grd = 'C';
		 }
		 else if(average < 70)
		 {
			 grd = 'F';
		 }
		 return grd;
	 }

	 outputFile << average << endl;
int main ()

{
	string name;
	int number_of_Students = 4,
		grade = 0;
	float average= 0;

ofstream outputFile;
outputFile.open("avegrade.txt");


	gradeloopFunction(main)
	averageloopFunction(average)

	outputFile << average << grd << endl;
	outputFile.close();

return 0;
}


The original looks like this:
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
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main ()
 
 
{
        string name;
        int number_of_Students = 4,
                grade = 0;
        double average= 0;
 
ofstream outputFile;
outputFile.open("avegrade.txt");
 
 
        for (int i = 1; i <= number_of_Students; i++)
        {
  cout << "Enter a name for student #" << i << " ";
  getline (cin, name);
  cin.ignore();
  outputFile << name << endl;
  //write the name to the text file
 
        int number_of_Grades = 3;
  for (int j = 1; j <= number_of_Grades; j++)
  {
   cout << "Enter a grade #" << j << " ";
   cin >> grade;
 
           while (grade > 100 || grade < 1)
           {
                   cout << "Invalid: Please enter a number between 1 & 100!" << endl;
                   cin >> grade;
           }
   //add the grade to the average
           cout << setprecision(1) << fixed;
           average = average + grade;
           average = average / 3;
           outputFile << average << endl;
  }
  //calculate the average and write to file. divide by 3
        }
 
        outputFile.close();
 
return 0;
}


Should I be initializing variables in main or the function as well?
i think i just dug myself a hole, i'm just to figure out what i'm doing wrong before i go to sleep

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
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

ofstream outputFile;
char grd;
int number_of_Students = 4,
	grade = 0;
float average= 0;
string name;


float gradeloopFunction()
{
	 for (int i = 1; i <= number_of_Students; i++)
        {
  cout << "Enter a name for student #" << i << " ";
  getline (cin, name);
  cin.ignore();
  outputFile << name << endl;
	 }
  //write the name to the text file
 
        int number_of_Grades = 3;
	 for (int j = 1; j <= number_of_Grades; j++) 
  {
   cout << "Enter a grade #" << j << " ";
   cin >> grade;

     while (grade > 100 || grade < 1)
	   {
		   cout << "Invalid: Please enter a number between 1 & 100!" << endl;
		   cin >> grade;
	   }
   //add the grade to the average
	   cout << setprecision(1) << fixed;
	   average = average + grade;
	   average = average / 3;
	   return average;
  }
}

	 char averageloopFunction()
	 {
		 
		 if(average >= 90)
		 {
			 grd = 'A';
		 }
		 if(average >= 80; average < 90)
		 {
			 grd = 'B';
		 }
		 if(average >= 70; average < 80)
		 {
			 grd = 'C';
		 }
		 else(average < 70)
		 {
			 grd = 'F';
		 }
		 return grd;
	 }
int main()
{
	outputFile.open("avegrade.txt");

	gradeloopFunction();
	averageloopFunction(average);

	outputFile << average << grd << endl;
	outputFile.close();

return 0;
}


im getting these errors
1
2
3
4
5
6
7
8
9
10
11
12
13
1>c:\users\zeit\documents\visual studio 2012\projects\project17\project17\source.cpp(57): error C2143: syntax error : missing ')' before ';'
1>c:\users\zeit\documents\visual studio 2012\projects\project17\project17\source.cpp(57): warning C4390: ';' : empty controlled statement found; is this the intent?
1>c:\users\zeit\documents\visual studio 2012\projects\project17\project17\source.cpp(57): error C2059: syntax error : ')'
1>c:\users\zeit\documents\visual studio 2012\projects\project17\project17\source.cpp(58): error C2143: syntax error : missing ';' before '{'
1>c:\users\zeit\documents\visual studio 2012\projects\project17\project17\source.cpp(58): warning C4552: '<' : operator has no effect; expected operator with side-effect
1>c:\users\zeit\documents\visual studio 2012\projects\project17\project17\source.cpp(61): error C2143: syntax error : missing ')' before ';'
1>c:\users\zeit\documents\visual studio 2012\projects\project17\project17\source.cpp(61): warning C4390: ';' : empty controlled statement found; is this the intent?
1>c:\users\zeit\documents\visual studio 2012\projects\project17\project17\source.cpp(61): error C2059: syntax error : ')'
1>c:\users\zeit\documents\visual studio 2012\projects\project17\project17\source.cpp(62): error C2143: syntax error : missing ';' before '{'
1>c:\users\zeit\documents\visual studio 2012\projects\project17\project17\source.cpp(62): warning C4552: '<' : operator has no effect; expected operator with side-effect
1>c:\users\zeit\documents\visual studio 2012\projects\project17\project17\source.cpp(65): error C2181: illegal else without matching if
1>c:\users\zeit\documents\visual studio 2012\projects\project17\project17\source.cpp(66): error C2143: syntax error : missing ';' before '{'
1>c:\users\zeit\documents\visual studio 2012\projects\project17\project17\source.cpp(76): error C2660: 'averageloopFunction' : function does not take 1 arguments
Last edited on
#include <iostream>

#include <conio.h>

#include <string>

#include <random>

#include <stdio.h>

#include <cmath>

using namespace std;

int main()
{

string characterclass, confirm;

int playerstrength, playerendurance, playeragility;

cout << "PREPARE FOR EVISCERATION!" << endl;

cout << "What kind of character would you like? (Warrior, Assassin or Ranger)";

cin >> characterclass;



if(characterclass == "warrior" || "Warrior"){
warrior();}

else if(characterclass == "assassin" || "Assassin"){
assassin();}

else if(characterclass == "ranger" || "Ranger"){
ranger();}
}

void warrior()
{

string confirm;

cout << "So you would like to be a warrior?(Y/N)";

cin >> confirm;



if(confirm == "y" || confirm == "Y"){

generatestats();}

else{

main();}
}

void assassin()
{

string confirm;

cout << "So you would like to be a assassin?(Y/N)";

cin >> confirm;



if(confirm == "y" || confirm == "Y"){

generatestats();}

else{

main();}

}

void ranger()

{

string confirm;

cout << "So you would like to be a ranger?(Y/N)";

cin >> confirm;



if(confirm == "y" || confirm == "Y"){

generatestats();

characterclass = "Ranger";} //this is where i have a problem

else{

main();}

}

void generatestats();







in line 52 and 56 you need to replace the ; with &&
if(average >= 80 && average < 90)

in line 71 you call averageloopFunction(average) but it is a function who doesn't take parameters.

BTW why is number_of_Grades smaller than number_of_Students?
Thomas the reason number_of_Grades is smaller because it takes 3 grades from input while the number of students is 4.

3 grades from 4 different students.

yeah i fixed the errors in 52 and 56 . im still getting 1>c:\users\zeit\documents\visual studio 2012\projects\project17\project17\source.cpp(66): error C2143: syntax error : missing ';' before '{'

and the argument error
so far i got this
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
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

ofstream outputFile;
char grd;
int number_of_Students = 4,
	grade = 0;
float average= 0;
string name;


float gradeloopFunction()
{
	 for (int i = 1; i <= number_of_Students; i++)
        {
  cout << "Enter a name for student #" << i << " ";
  getline (cin, name);
  cin.ignore();
  outputFile << name << endl;
	 }
  //write the name to the text file
 
        int number_of_Grades = 3;
	 for (int j = 1; j <= number_of_Grades; j++) 
  {
   cout << "Enter a grade #" << j << " ";
   cin >> grade;

     while (grade > 100 || grade < 1)
	   {
		   cout << "Invalid: Please enter a number between 1 & 100!" << endl;
		   cin >> grade;
	   }
   //add the grade to the average
	   cout << setprecision(1) << fixed;
	   average = average + grade;
	   average = average / 3;
	   return average;
  }
}

	 char averageloopFunction()
	 {
		 
		 if(average >= 90)
		 {
			 grd = 'A';
		 }
		 if(average >= 80 && average < 90)
		 {
			 grd = 'B';
		 }
		 if(average >= 70 && average < 80)
		 {
			 grd = 'C';
		 }
		 else(average < 70)
		 {
			 grd = 'F';
		 }
		 return grd;
	 }
int main()
{
	outputFile.open("avegrade.txt");

	gradeloopFunction();
	averageloopFunction(average);

	outputFile << average << grd << endl;
	outputFile.close();

return 0;
}
it's still not finished but it's as close as i can get without sleep
line 60 else(average < 70) must be else if(average < 70)

line 71 averageloopFunction(average); must be averageloopFunction();

This should fix all compile errors.
Topic archived. No new replies allowed.