Can you also please post a snippet of code with more functions in this code. I get how to make functions and all but I don't get where I would use it and where I would like put it in this program
Googling something takes about 5 seconds, and this website has a surprisingly well written tutorial as well. A crucial part of being a good programmer is being able to do research, but I'll help you out anyways: http://lmgtfy.com/?q=c%2B%2B+functions+tutorial
Since you say you know how to write functions, think about why they're useful. In your program you're executing roughly the same pieces of code over and over with minor changes. Instead of typing them out each time, why not write yourself one or two neat little functions and call them every time you need to get input?
As for your problems with Code::Blocks, you most likely didn't have g++ installed on your computer. I'm assuming you've fixed it now anyways :/
You've clearly ignored both my own posts, as well as everyone else who have tried to help you, which I find insulting.
Now let's use our "expert programmer" analysis skills to fix your compiler errors. Because your compiler says you are using variables that aren't declared in your function, it's safe to assume that your problems are only in this function. Let's take a look at it from the computers perspective:
Line 1: Output a string to a stream using the cout object.
Line 2: Read from the input stream using the cin object, and store the value in dnum1. WAIT!!??!!!!!111one, I have no idea what dnum1 is, is it a class, a function, a variable, a bird, a plane, superman? Compiler error.
Line 3: Output a string to a stream using the cout object.
Line 4: Read from the input stream using the cin object, and store the value in cchar. Again, what is cchar? I haven't head of it.
See where I'm going here? Now for the third time, I recommend you use pastebin so you don't have to spread your code across multiple posts which is an inconvenience for both you and the people trying to help you. And if you need me to hold your hand through a problem again because you're scared of your compiler please just ask.
While I'm at it please stop bumping your posts with thought-provoking messages such as "help plz" or "?."
Lastly, it's safe to assume that the only errors in your program at the moment are in your new function, so there isn't a need to post everything else and make it harder for the people trying to help you to do so?
sorry i actually wasnt quite fond of that website. i didnt really get how to use it. and as for the functions im still trying to implement them in my code. 2morrow ill work on what you said in the last post and im sorry if im being in polite ill be more polite...ill start using pastebin
ok i used pastebin to post my code.press the link.i fixes the function but doesnt that function just make that program longer??? http://pastebin.com/m2hGfcCM
OMG... You miss the entire point of using a function! You're supposed to make a function to carry out repetitive lines of code! But all you've done is cut-paste a section of code, put it in a function and then called that function... Goodness... Ohk, here's what you do, write four functions, each for the four operations, viz (+), (-), (*), (/) which takes two arguments... Then wherever you're using addition, instead of calculating the expression again and again, just call the function. First just write the four functions, and show them, via Pastebin only...
If you use proper indentation you should see that things doesn't line up. The do loop has no ending } while (...);. You are missing break; on a number of places and some code is unreachable because it is placed after a break;
I think the problem here is, that you code as you go... Don't do that.. Plan out what you want.. Try and think out the repetitive lines of code, and where your code becomes unreadable or unmanageable.. Write out a format of a sample output.. Imagine what you'd want in a good proper calculator. What good is a calculator, that can do ONLY one type of operation on several numbers! Think out an algorithm for your basic program, and then start... This way, you won't hit roadblocks as far as logic is concerned, your code will be much much cleaner, and the program will be readable and user-friendly... If you're doing this calculator thing for just some practice, I'd suggest starting over.
ok and how would i do the function for lets say addithion.ok i call the function at all of the case'+'s but on each one you add a different amount of numbers.so how will that work because i add a diferent amount of numbers on each case'+'?
float add(float a, float b)
{
return (a+b);
}
void main()
{
//blah blah blah
float a, b, c, d, e;
cout<<"Enter 5 numbers to add: ";
cin>>a>>b>>c>>d>>e;
cout<<"The result is: "<<(add(add(add((add(a, b)), c), d), e)); //First adds a and b, then their result to c, etc etc...
}
Ohk, here's what I'm gonna do... I'm gonna write a calculator program in my free time in my way, post it as "My Calculator" and then you can see the difference.. (I'm not trying to be condescending, just trying to show how much simpler and efficient a program can be...)
When running a C++ program, the operating system looks for the main function to start running the program (the only function the operating system explicitly calls). This means that the name main is reserved for the main function, and in the above program you've declared your own version of main that returns a void value. You need to declare main to return an int.