Hello all... I am new to c++, and I am trying to figure this out. I have to call on 4 functions in a program, and I can not use any Global variables at all.
The first function is to be used to collectInfo() of string and integer values, and the second is to be used to showInfo() gathered. determineAverage(), DisplayWorstAverage Where I am stuck is,I am being told to call this from the main function. Is using a prototype for these functions different than declaring a global variable before the main function?
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// prototypes here ?
int main()
{
string bowlerName[10];
int bowlerScore[10];
double totalScore = 0;
double averageScore = 0;
int i = 0;
int foo(); // this is a function prototype; it's also a declaration
int bar; // this is a global variable
int main()
{
bar = foo(); /* function foo() is being called and the return value
is being stored in global variable bar */
}
int foo()
{
// foo's code goes here; this is a function definition
}
The prototype is not needed if the function is defined before being called, because a definition is also a declaration:
1 2 3 4 5 6 7 8 9 10 11
int bar;
int foo()
{
// foo's code goes here
}
int main()
{
bar = foo();
}
Please use [ code ] [ /code ] tags (minus the spaces) to post code. In the above snippet, you forgot to declare results (it must be a variable of type string, global or not). And when you define it, you must write the function signature again:
1 2 3 4 5 6 7 8 9 10 11 12 13
string collectInfo(); // declaration
// some code
int main()
{
// code
}
string collectInfo() // definition
{
// code goes here
}