The professor wants us to create a program that displays the Average of 3 Grades. Each input of the grades must be stored with a function and then the Result of the Average is to be displayed with a void. I ask some questions but he answers that he cannot help with my logic in the programming :/
#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std;
int firstgrade(int a);
int secondgrade(int b);
int thirdgrade(int c);
void result ();
int main()
{
string ans = "n";
do
{
cout << "This program will calculate the Average of 3 Grades" << endl << endl;
cout << firstgrade;
cout << secondgrade;
cout << thirdgrade;
cout << result;
cout << "Would you like to repeat the program? (s/n) : ";
cin >> ans;
} while (ans == "s" || ans == "S");
return 0;
}
int firstgrade (int a)
{
int grade1;
cout << "Enter the first grade :";
cin >> grade1;
return grade1;
}
int segundanota (int b)
{
int grade2;
cout << "Enter the first grade :";
cin >> grade2;
return grade2;
}
int terceranota (int c)
{
int grade3;
cout << "Enter the first grade :";
cin >> grade3;
return grade3;
}
void result ()
{
int result;
result = primeranota+segundanota+terceranota/3;
cout << endl << "The average of the 3 Grades is : " << result << endl;
}
Well I am not even sure that I can pass the value of one function by calling it in the void function to do the Average. My question is how would I be able to use the function correctly to achieve the result. I have read alot but none gives me a correct idea to use the function in that way.
I think you need to read up on calling functions. You are using the address of the function not calling the function with the parameters required. http://www.cplusplus.com/doc/tutorial/functions/
#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std;
int firstgrade();
int secondgrade();
int thirdgrade();
void result ();
int main()
{
int a,b,c;
string ans = "n";
do
{
cout << "This program will calculate the Average of 3 Grades" << endl << endl;
cout << firstgrade();
cout << secondgrade();
cout << thirdgrade();
a=firstgrade();
b=secondgrade();
c=thirdgrade();
cout << result(int a, int b, int c);
cout << "Would you like to repeat the program? (s/n) : ";
cin >> ans;
} while (ans == "s" || ans == "S");
return 0;
}
int firstgrade ()
{
int grade1;
cout << "Enter the first grade :";
cin >> grade1;
return grade1;
}
int secondgrade ()
{
int grade2;
cout << "Enter the first grade :";
cin >> grade2;
return grade2;
}
int thirdgrade ()
{
int grade3;
cout << "Enter the first grade :";
cin >> grade3;
return grade3;
}
void result (int a, int b, int c)
{
int result;
result = a+b+c/3;
cout << endl << "The average of the 3 Grades is : " << result << endl;
}
I cant figure out why all 3 functions have the same error that they do not return a value. I am not sure if it is because the cin is inside the function or if it is a syntax error. Will continue to read on functions though.
Oh yes sorry that was a error when translating from spanish to english. The program must accept 3 grades to calculate the Average GPA in the void function. But each grade must be within a different function. If not I would just accept the 3 grades with a space and add them to 1 function only.
cout << "This program will calculate the Average of 3 Grades" << endl << endl;
a=firstgrade();
b=secondgrade();
c=thirdgrade();
result(a, b, c);
cout << "Would you like to repeat the program? (s/n) : ";
cin >> ans;
Yes wwwiii I changed the code to that way because then I would repeat the same if I used it the way I had it. But VB still gives me same error for the 3 functions. It says that the functions are not returning value.