Very beginner question

Please help me: 1. fix this (xD) 2. explain how it works

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <string>

using namespace std;

void coffeeType();

int main(coffee){
	string coffee;
	cout << "Enter your favourite type of coffee: " << endl;
	cin >> coffee;
	return 0;
}

void makeCoffee(string type){
	cout << "Making a cup of " << type;
}
Last edited on
int main(coffee){ <-------------- you can't do this. main should either have no parameters or some very specific ones that I won't go into here that govern its commandline (and by proxy drag and drop in windows) parameters. it should just be int main() here.

void coffeeType(); <------------- this is legal but you do not make a body for this function and you may have problems because of this.

void makeCoffee(string type){ <---------------- this function is never used.

putting all that together, we get:

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


 #include <iostream>
#include <string>
using namespace std;

void makeCoffee(string type); //changed to the function you actually HAVE

int main()
{ //fixed misaligned brace
	string coffee;
	cout << "Enter your favourite type of coffee: " << endl;
	cin >> coffee;
        makeCoffee(coffee); //call your function here!
	return 0;
}

void makeCoffee(string type)
{
	cout << "Making a cup of " << type;
}




I am unsure of what the problem is....

Would you please post the strange output you get.

As for not understanding what you wrote, I can suggest looking at the c++ tutorial on this website that can be found via the following link:
http://www.cplusplus.com/doc/tutorial/

More specifically, I suggest looking at the Classes I portion of the tutorial that can be found using the following link:
http://www.cplusplus.com/doc/tutorial/classes/

I suggest looking at the Basic Input/Output tutorial found at the following link:
http://www.cplusplus.com/doc/tutorial/basic_io/

Unfortunately, I can't help you any further then that because I would be rehashing what's on the tutorial. Please post more specific questions to aid me in helping you.

I hope that helps.
Last edited on
thank you very much, you may think this is a pointless question, but i started c++ specifically for the memory allocation/management and this has really helped. thanks
Topic archived. No new replies allowed.