Thread: functions and switch statement

  1. #1
    Registered User
    Join Date
    Oct 2003

    functions and switch statement

    I have this program for class and I am almost done but I am stuck on this part. Basically, you have to write a program to print your name. You run the program and it makes a .gnuplot file and a .png file. Up until that point, I am fine.

    The problem comes in when I try to ask the user to input what s/he wants printed to the screen, either first name, last name, or both names. I know to declare a variable for that, then put it into a switch statement and direct it to go to that segment of code (depending on which of the three options the user entered).

    For example, I tried making a larger function of smaller functions, meaning I took my first name, Ryan, and had each of those letters in their own function. Then I made a function to enclose all of those letters into a larger function, functionFirstName, so I could call on it in the swtich statement. That way it would print out just the first name and stop there (assuming the user just wanted my first name printed). I'd also need to do the same for the last name, and for both first and last name so I would just use the same approach.

    But this doesn't seem to work. Is it legal, or is there a better way to go about this?

    The main errors I get for each function in the program are:
    -warning: data definition has no type or storage class
    -error: parse error before numeric constant
    -error: conflicting types for `writeR'
    -error: previous declaration of `writeR'
    ... etc.

    The program works fine until I throw in this larger enclosing function.

    Any ideas? Thanks in advance!

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    Post the code.
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

  3. #3
    Registered User
    Join Date
    Oct 2003
    Last edited by rmathus; 11-29-2003 at 07:32 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting the switch statement to work.
    By mtymightymike in forum C Programming
    Replies: 7
    Last Post: 10-15-2008, 06:32 PM
  2. Functions in a switch case...
    By yaya in forum C++ Programming
    Replies: 1
    Last Post: 04-30-2008, 03:58 AM
  3. Applying the Switch and some other functions.
    By kendo411 in forum C Programming
    Replies: 9
    Last Post: 01-20-2004, 09:55 AM
  4. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  5. switch statement / command line
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 12-20-2001, 04:21 PM