1 question 3 possible answers how do I goto a routine based on the answer

I have a question which has three possible answers.

How do I write code that takes the answer to the question and then takes it to another piece of code which does a calculation and returns a result?

I have tried the scanf function but I am un able to achieve my desired result.

Use a case then function, so you would get whatever data you needed from the cases, whether a bool, int or char then you would send it to a function to do the work.
Sorry I googeled it but I cant find a description of a "case then function"
Use a switch statement:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

int main()
{
    int num = 0;
    std::cout << "Enter a number from 1 to 3 ";
    std::cin >> num;
    switch (num)
    {
        case (1):
        std::cout << "One";
        break;
        case (2):
        std::cout << "Two";
        break;
        case (3):
        std::cout << "Three";
                    break;
        default:
        std::cout << "Number not 1-3";
        break;
    }
}
when I have tried to compile this I get several errors. The first which I suspect which is causing the rest is

iostream no such file or directory

I changed it in the code to isotream.h and got the same error.

the second error is syntax error before ':' token

the third error is duplicate label 'std'

sorry I am really lost here

Which compiler are you using bro?
post your code so we can look.
Hi I am using V gvim as my compiler

I basically copied and pasted the code from the above

#include <iostream.h>

int main()
{
int num = 0;
std::cout << "Enter a number from 1 to 3 ";
std::cin >> num;
switch (num)
{
case (1):
std::cout << "One";
break;
case (2):
std::cout << "Two";
break;
case (3):
std::cout << "Three";
break;
default:
std::cout << "Number not 1-3";
break;
}
}

This has a way of making me feel really stupid


Compile as C++ code: > g++ -std=c++11 -pedantic-errors -Wall -Wextra my_program.cpp
visual c++ dude. it's like it was made for beginners and it's free!
Thanks guys but now I am right out of here lost. compile as c++ code my file name is 3.c the above is so so alien to me. Visual c++ well this is just out my capabilities I think
I thought I was learning c++ but the above code looks like nothing I know looks like I am learning c so who knows
> I thought I was learning c++ but the above code looks like nothing I know looks like I am learning c

If std::cin >> num; looks completely unfamiliar, you are learning C.

In that case, see:
http://www.cs.utah.edu/~zachary/ispmma/tutorials/io/io.html
Topic archived. No new replies allowed.