C++ Problem

Started by
1 comment, last by evervoid 16 years, 4 months ago
hey, i'm just starting to use C++ and i'm trying to get this code to work, it compiles but for some reason the second function doesn't work, heres the code:
 #include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

string input;
string output;

int b;

int options()
{
    int b;
    
     cout << "1. DFO\n";
     cout << "2. WoW\n";
     cout << "3. WC3\n\n";
     cin >> b;
     
     return(b);
}

string func(int a)
{      
     if(a == 1)
     {
         string output = "DFO";
     } else if ( a == 2) {
            
            output = "WoW";
     } else if (a == 3)  {
            
            output = "WC3";
     }
     return (output);
}

int main()
{
    int choice;
    string out;

    choice = options();
    cout << func(choice);
    cin >> out;
}
    


any ideas?
Advertisement
The only part of the second function that won't work is when a == 1. Declare output at the start of the function instead of in the "if" statement.
thanks :) it works now. and that was my first time using functions :D i think i'm gettin better :)

thanks!

This topic is closed to new replies.

Advertisement