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.
#include <iostream>
usingnamespace 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;
}
elseif (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.
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...
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.
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?