functions help

closed account (jGAShbRD)
i wanted to make a function and then checks if the user reboot or not. and in the int main function i want to call from that function. the code i have so far isnt working and need help.


#include <iostream>

void support(std::string apple){
std::cout << "Hi!\n";
std::cout << "Did you reboot? Enter Y if yes or N if no.\n";
std::cin >> apple;
if (apple == "Y"){
std::cout << "Restore";
}
else if ( apple == "N"){
std::cout << "Reboot";
}
else{
std::cout << "Error";
}
}

int main(){
std::cout << support();

}
support's return type is void. That means it doesn't return any value.
printing is not the same thing as returning a value.
http://www.cplusplus.com/doc/tutorial/functions/

All of the logic appears to be happening inside support(), so just have main be:
1
2
3
int main() {
    support();
}


Your apple variable should not be a parameter of the function, because its value is simply overwritten.
Your function should look like:
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <string>

// ...

void support() {
    std::string apple;
    // ...
    std::cin >> apple;
    
    // ...
}

Note that <string> should be #included if you use std::string objects.
Last edited on
Topic archived. No new replies allowed.