If/else if statements not running as planned

Good evening gang, I just came across this forum and had to join, I also thought it would be a good place to see if some one can help me. Currently I'm new to programming (2 months of self taught coding in c++). I'm working on a program and can't seem to get it to run.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>

    using namespace std;

    class introduction
    {
        public:
        void introtext()
        {


            cout<<"                 ***This is a test made by me***"<<endl;
            
       }
    };
    class inputvariabe
    {
        public:
        void inputtext()
        {
            int x;


            cout<<"Please enter a name"<<endl;
            cin>>x; // I know these lines are silly I’m just testing my skills on this program


                {
                    cout<<"Hello and welcome"<<endl;
                    

                }
        }
    };
    class proceedoptions
    {
        public:
        void question()
        {

            char response;

            cout<<"Choose Y or N ";
            cin>>response; //attempting to run this in a yes input/no input to continue, I get no errors and appears correct, but won't run as planned, when I run it with just this class on a new project, it runs fine.
            if (response == 'Y')
            {
                cout<<"Cool, you hit yes"<<endl;
                
            }
            else if (response == 'N')
            {


            cout<<"Why didn’t you type no?"<<endl;


            }

        }
    };

int main()
{
    introduction io;
    io.introtext();
    inputvariabe it;
    it.inputtext();
    proceedoptions qo;
    qo.question();


}


If anyone can help me it would be greatly appreciated.
Hi !
First of all welcome to the forum :D
Let me offer a few comments to get u moving again.

I can take a guess at what's wrong.
Line 24 prints "Please enter a name" to the screen then line 26 waits for user input. So the user puts in a name (in characters) but cin isn't able to store characters into the 'x' variable since 'x' is declared as an integer. cin basically crashes and line 44 doesn't wait for user input as expected...This is a good example of why it's so important to be prepared to handle all user input because an error at 1 line can cause other strange ones that are hard to detect in other places...

Just change line 21 to a char array or a string (#include <string.h>) and u shouldn't have problems.

Also, line 62 declares the entry function main to return an integer...line 71 should have that return value...

U might also want to put a system("PAUSE"); or a dummy 'cin' call at the end of main() to allow the user to see any final output message like line 54 which is never seen because the console closes too fast.

GL !
Last edited on
Thank you so much! I appreciate your answer it helped me within a matter of seconds reading that. I do not have much experience in c++ strings. Also, how long will it take before I learn graphics (like building excel like charts with color)?
U'r welcome.
There's too many factors to know how long it'll take to learn what it'd take to make a program like excel...It can take a good 6months to a year to get to a decent handle of the basics...then a lifetime to master them :p

If ur aim is to make graphical apps then (after u'v got a decent foundation with the basics) don't spend too much time making 'graphical' console apps as it is not really a good stepping stone as many beginners tend to think...
My goal is to make an application with real time data, and charts/graphs of data. Would c++ be the best route for this, or java?
Depends on where it'll be deployed... If it's for the web then java. If it's for a mobile then java again. If it's for a desktop then I prefer C++.
There's no strict rules though - C++ and java are versatile languages and very similar in many ways...Learn one well and then the other will come easy.
Ok, then I will stick to c++, I plan on having this downloaded to a disc possibly. I know I have a long ways to go but have already started making some progress on a script prototype of the software. I have a somewhat decent knowledge on the basics (I just have trouble every now and then using them all at one program). How does one go from printing on cmd prompt script to something else? I really am determined to finish this software by 2015 as I'm a college student who can spend hours working on it.
include a graphics library r u interested in cross plat form or os specific? if it is os specific which os?
Cross platform would be the best. However a single platform would be nice if it saves lots of time for the first finish of the project. I don't know much on graphics, I thought there was no graphics library?
I don't know much on graphics, I thought there was no graphics library?


There are literally hundreds of graphics libraries available for C and C++. Thousands. Wouldn't be surprised if there were more. Lots.

Topic archived. No new replies allowed.