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!
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...
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.