Im not to sure whats going on in my code.
granted ,I am a noob.
What I'm trying to do is create a function and then call that function in the mai.n
I think I have this covered but I just cant get past these syntax errors, which is very frustrating since I think I should be able to spot that.
I built the function from the template provided here at cplusplus.
Also this is my first program outside of hello worldso my experience is very lacking.
ok so heres the code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
usingnamespace std;
int multiplication(int a ,int b)
{
int r;
r=a*b;
return(r);
}
int main()
{
int y int x;
cout<<"enter a number: ";
cin>>y;
x = multiplication (y,2);
cout<<"the result is: "x;
return 0;
}
Also I'm not really trying to be told what to do , just would like to be pointed in the right direction so I can see what I'm missing
thanks to all ahead of time
ok cool I did fix this and it works . I do understand where i went wrong now.
There is another issue now.
It seems when I compile and debug (visual c++ express)
it opens the console and ask for the input
I enter the input
the console blinks the output (line 16) and then the console disappears
I read in another forum about about a system pause command but this seems kind off excessive
am I missing something like <<endl or something ?
If you're using MS Visual Express why not just use the 'Start without debugging' option (cntl-F5).
It will hold the console window open for you automatically.
I want to thank all that replied to this thread.All of the reply were very helpful and did make a difference in the final code.Also Ctrl+f5 was exactly what I was looking for. in case anyones interested in the final product
#include <iostream> //headers
usingnamespace std;
double doubleit(double a ,double b) //function for multiplying usr input * 2
{
return a*b; //body of function
}
double funct2(double c, double d, double e) //function for adding and dividing the output from function doubelit
{
return (c+d)/e; // body of function
}
void main ()
{
double number; double x; double z; //variable declaration
cout<<"Enter a number: "; // asks usr for input
cin>>number; //usr input is variable number
x = doubleit (number,2); //funtion call to doubleit
cout <<""<<endl; //skips a line in display
cout <<"The number Doubled is: "<<x<<endl; //output of doubleit to usr as x
z=funct2(x,7,2); //function call to funct2
cout <<""<<endl; // skips a line in
cout <<"The (Doubled number + 7) / 2 is : "<<z<<endl; // output of funct2 to usr as z
cout <<""<<endl; // skips a line in display
return; //return to main end of program
}