Program responce & strings *HELP*

Hi, Im new to C++ and Im just mucking around with it to see what I can create, normaly Im quite self explanatory when It comes to things like this but I really can't get my head around this. Basicly I want to make it so that when you say something in command prompt, like this "Take me to google" then it will do this "cout << "Sure, 1 second" << list << endl;" I was hoping to add a list of responces that the program would do and actions. Someone please help me on this It would help me out much :)

Here's the rest of the code I was working on.

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>
#include <string>
#include <windows.h>

using namespace std;

int main(int argc, char* argv[])
{
	const int MAXRESPONCES = 5;
	string name;
	string cpuname;
	string list[MAXRESPONCES] = {"

#define cpuname "James" //Defines the cpu name to respond to. Change it if you wish.

cout << "Hello, my name is: " << cpuname << endl;
cout << "And what is your name?" << endl;
cin >> name;
cout << endl << "Hello " << name << " and how can I help you today?" << endl;

return 0;

} 
string list[MAXRESPONCES] = {"

What's this? It looks like there's a whole lot of stuff missing at the end of that line.
O I was going to put like a list of websites or something like that, that would be triggered by the client, once again Im confused how to make it so that you type something and it would responce xD
Hi Hazukiy & welcome to cplusplus forums,

There are someof immediate small problems:

 
include <iostream>


Is missing the # at the start ( It's not the same as the other #includes);

and
 
string list[MAXRESPONCES] = {" 


is a syntax error because of the missing brace and missing double quote. This is also a problem because you haven't initialised the array - which is very important and the cause of a lot problems. BTW MAXRESPONCES is spelt MAXRESPONSES

I seem to be telling nearly everyone not to do this:

 
using namespace std;


It is is only a matter of style and a technical point, but it makes things easier for the compiler / optimiser because it does not bring in heaps of other stuff that isn't used. People do it all the time because they see it in text books. If you are using cin and cout and string then do this:
1
2
3
using std::cin;
using std::cout;
using std::string ;


You could also initialise name like this, and describe what it is for:
 
string name = ""; // the other persons name 


There is no need to have the variable cpuname because you have defined it with #define, however the convention is name it with capital letters like this
1
2
#define CPUNAME
"James" //Defines the cpu name to respond to. Change it if you wish. 


Be aware that all this does is replace all occurrences of CPUNAME
with "James".

Now having said all that, you should get used to using the debugger in your IDE, put cout statements everywhere to see what is happeneing to your variables.

Other important things are the naming of variables to something meaningful. Don't worry I seem to be telling everyone in the beginners forum about this also!
Could list[MAXRESPONCES] be ResponseList[MAXRESPONSES ] ? You need to put values into this array, (in the definition of the array is the easiest)

Next you need a for loop to cycle through the array using cout statements to present a "menu" to the user.

Then use a cin to store a response from the user.

Then a switch statement to carry out an action for a particular response.

Hope this helps.

Cheers TheIdeasMan



Sorry forgot one thing.

The #define goes at the top of file after the #includes.

TheIdeasMan
Topic archived. No new replies allowed.