First "program"

Posts 1–14 of 14 · Page 1 of 1
First "program"
Hi, I'm trying to write a simple DOS program that asks basic questions and responds with another question, but my problem is, say my program asks "How are you today?" I respond with "Good" and then it basically shuts down. that's the best I can explain it I guess. so my question is, How can I get my program to accept words, or letters? do I have to use if/else lines? or can I use some kind of command so I can put "Good" and it continue?

Thanks in advance. guys. Here's the code, please don't laugh. it's my first I've written by myself.

Code:
#include "stdafx.h" // Uncomment this line if using Visual Studio
#include <iostream>

int main()
{
    using namespace std;
    cout << "Hello, nice to meet you. How are you today?";
    int x;
	cin >> x ;
    cout << "That's good. How old are you?" << endl;
	int y;
    cin >> y;
	cout << "Oh, What a young age " << y << " is" << endl;
    cout << "where are you from?" << endl;
	return 0;
}
you are writing "good"

First of all, "good" is a string, not an int (an int stores numbers, not words)
And because of the fact that you are writing good, he reads the first letter, saves it's dec code to the int, and saves the rest on the keyboard buffer, using it on the next Cin >>

You probably don't understand a shit of what i'm saying, i advice you to follow a tutorial, and not randomly typing things that you don't understand yet.
Quote Originally Posted by 'Bruno View Post
you are writing "good"

First of all, "good" is a string, not an int (an int stores numbers, not words)
And because of the fact that you are writing good, he reads the first letter, saves it's dec code to the int, and saves the rest on the keyboard buffer, using it on the next Cin >>

You probably don't understand a shit of what i'm saying, i advice you to follow a tutorial, and not randomly typing things that you don't understand yet.
Believe it or not, I know Int stores number not words, I posted the code to show where I'm at, in hopes someone would tell me what I could use to store words.

I'm also reading a tutorial, figured I learned enough to make a simple program. Apparently, I haven't. so I came here, asked simple question, what can I use to store words, if anything, or if I must use if/else.

no need to be prude about it. just a question.

Regardless, I'm gonna continue reading the guide in hopes of solving my problem...
Quote Originally Posted by Does it Matter View Post
Believe it or not, I know Int stores number not words, I posted the code to show where I'm at, in hopes someone would tell me what I could use to store words.

I'm also reading a tutorial, figured I learned enough to make a simple program. Apparently, I haven't. so I came here, asked simple question, what can I use to store words, if anything, or if I must use if/else.

no need to be prude about it. just a question.

Regardless, I'm gonna continue reading the guide in hopes of solving my problem...
Keep in mind that i wasnt being rude. Otherwise I would not explain you what was wrong.

Here's something simple about storing chars using arrays, but i advice you to look to the stuff before that specific page.

http://www.cplusplus.com/doc/tutorial/nt cs/ fix the link first.. removing the space
This code is bothering me so much lol....learn before you program. By the looks of this you probably only looked at tutorials 1 or 1 and 2 and then started to make your own stuff...
std::string
Quote Originally Posted by Fovea View Post
std::string
easiest path is not always the better.. just in my opinion..
Quote Originally Posted by 'Bruno View Post
easiest path is not always the better.. just in my opinion..
Mindlessly allocating memory is always a poor choice.
nice,
But why stdafx.h? you can do it without if you are making an empty project
1 line less is more time for the rest
Code:
#include "windows.h"
#include <iostream>

int main()
{
char answer[11];
    using namespace std;
    cout << "Hello, nice to meet you. How are you today?" << endl;
	cin >> answer ;
    cout << "That's good. How old are you?" << endl;
int y;
    cin >> y;
	cout << "Oh, What a young age " << y << " is" << endl;
    cout << "Where are you from?" << endl;
char place[11];
cin >> place;
cout << "Wow...I really dont care you can press Alt + F4 anytime now" << endl;
Sleep(5000);
	return 0;
}
I wrote this from my phone...
why would you say that they can press alt f4 if there is a return 0 right after cout..no pausing to see the message anyways.
Dude it was just for fun...gosh..I was messing around.
Quote Originally Posted by aanthonyz View Post
Dude it was just for fun...gosh..I was messing around.
where is the fun in things you will not see?
I can see it when im coding it but not when im running....whatever...grrr...
Posts 1–14 of 14 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Talk with us