C++ Quiz help.

Okay, so I am making a quiz for my c++ class, with cout and cin. And I have alot of text that i place in different functions, but what return type will the function have? All it does is print something to the screen:


1
2
3
4
5
6
7
8
void PrintPartTrue () {

    cout << "Okei, that was the first quiz, and you liked pizza and cake..." << endl ;
    cout << "So here is some more questions..." << endl << endl ;


 // Look after return type...
  return 0;


I get an error when I type return 0 ; Please help me!
In a void function you can't return anything. You may add return;, if you want to exit the function before executing all of it, but you don't have to.
void in front of a function name means this function return no value?
Correct.
you may use getch(); instead of return.
Void means null or empty so the function should also be empty.ie. it should return no value. Void are generally used to print something or store something to variables. Fuctions like int,float etc return a value...
What does an input function have to do with return types?
functions can be used toreturn a type, for instance, say you want to send 2 variables to a function and get their sum, you could do it this way

1
2
3
4
5
int add(int a, int b){
 int sum;
 sum = a + b;
return sum;
}


then you can print out like this

cout << add(1, 2) << endl;

output:
3

as you can see the return type is the type you want to return. if you wanted double, float, int, etc.. just declare the type. When you get further into your understanding, you will learn how to create classes and making classes that return class types.
Topic archived. No new replies allowed.