|
From: Ramana K. <ra...@my...> - 2002-09-18 10:40:53
|
You do not use the type "int" when you are using the - operator:
NumberThree = int NumberOne - int NumberTwo;
is wrong syntax.
you need instead:
NumberThree = NumberOne - NumberTwo;
but for this to work, the function ThirdNumber(int) needs to take NumberOne
and NumberTwo as parameters.
so you need to put
ThirdNumber(int,int,int);
as the definition. and in the main function, you call it like this:
ThirdNumber(NumberThree,NumberTwo,NumberOne);
you do not call functions with their return type and argument types either:
int FirstNumber(int NumberOne);
is wrong syntax (this is the call, not the definition).
you need instead:
FirstNumber(NumberOne);
you also need to use references, because the data you get from the user does
not survive the local scope of the function.
maybe i just write out your program correctly, removing syntax errors (but
not improving code):
#include <stdio.h>
#include <iostream>
#include <string>
/*
This program in designed to take input from the user,
in the form of a number and compute the output.
The program is then to display the output back to the user.
*/
int FirstNumber(int&); // Function Definitions
int SecondNumber(int&); // Function Definitions
int ThirdNumber(int,int,int); // Function Definitions
// FirstNumber Function
int FirstNumber(int NumberOne)
{
cout << "Enter how much money you had this morning $";
cin >> NumberOne;
}
// SecondNumber Function
int SecondNumber(int NumberTwo)
{
cout << "Enter how much money you have now $";
cin >> NumberTwo;
}
// ThirdNumber Function
int ThirdNumber(int NumberThree, int NumberTwo, int NumberOne)
{
NumberThree = int NumberOne - int NumberTwo;
cout << "You have spent $" << NumberThree << " dollars today " << endl;
}
// Main Function
int main(int argc, char *argv[])
{
int NumberOne;
int NumberTwo;
int NumberThree;
FirstNumber(NumberOne);
SecondNumber(NumberTwo);
ThirdNumber(NumberThree,NumberTwo,NumberOne);
system("PAUSE");
return 0;
}
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of John Ellison
Sent: Wednesday, 18 September 2002 8:00 PM
To: dev...@li...
Subject: [Dev-C++] Newbie Needs Help
Gudday All,
I have a small problem which I cant seem to find the answer to. I was
hoping that someone could help. I am just beginning to learn c++, so the
code is not to complex. My problem lies in the compilation process. I am
unsure as to how to fix the compilation error.
Thanks to everybody.
Have a good one.
John
Here is the compilation error.
32 six.cpp parse error before `-'
And here is my source code :-
#include <stdio.h>
#include <iostream>
#include <string>
/*
This program in designed to take input from the user,
in the form of a number and compute the output.
The program is then to display the output back to the user.
*/
int FirstNumber(int NumberOne); // Function Definitions
int SecondNumber(int NumberTwo); // Function Definitions
int ThirdNumber(int NumberThree); // Function Definitions
// FirstNumber Function
int FirstNumber(int NumberOne)
{
cout << "Enter how much money you had this morning $";
cin >> NumberOne;
}
// SecondNumber Function
int SecondNumber(int NumberTwo)
{
cout << "Enter how much money you have now $";
cin >> NumberTwo;
}
// ThirdNumber Function
int ThirdNumber(int NumberThree)
{
NumberThree = int NumberOne - int NumberTwo;
cout << "You have spent $" << NumberThree << " dollars today " << endl;
}
// Main Function
int main(int argc, char *argv[])
{
int NumberOne;
int NumberTwo;
int NumberThree;
int FirstNumber(int NumberOne);
int SecondNumber(int NumberTwo);
int ThirdNumber(int NumberThree);
system("PAUSE");
return 0;
}
|