get_item_price

T

tomakated

Hi, i'm new here and I can't get my get_item_price() function to work I
need it to take in 4 items

int main()

{

double item1, item2, item3, item4, lowest=0, total;

char response;



instructions();

item1 = get_item_price();

item2 = get_item_price();

item3 = get_item_price();

item4 = get_item_price();

total = item1 + item2 + item3 + item4;

cout << “Do you have a coupon for this purchase? \n" ;

response = getresponse();

if (response == 'y')

{ lowest = findcheapest(item1, item2, item3, item4);

total = total – lowest;

}

printresults (response, item1, item2, item3, item4, total, lowest);

}

and so far all I have is this;
#include <iostream>
#include <iomanip>

double findcheapest(double, double, double, double);
void printresults (double, double, double, double, double, double,
double);


int main()
{
double item1, item2, item3, item4, lowest=0, total;
char response;

instructions();
item1 = get_item_price();
item2 = get_item_price();
item3 = get_item_price();
item4 = get_item_price();
total = item1 + item2 + item3 + item4;
cout << "Do you have a coupon for this purchase? \n" ;
response = getresponse() ;
if (response == 'y')
{ lowest = findcheapest(item1, item2, item3,
item4);
total = total - lowest;
}
printresults (response, item1, item2, item3, item4,
total, lowest);
}


void get_item_price()
{
double i;
cout << "Enter the four item prices you want to buy.\n"
cout << "Item1: ";
cin >> i;
while (i<0)
{
cout << "Please enter a positive number: ";
cin >> i;
}

int getresponse()
{
while ((response == 'y' ) || (response == 'Y')
{
cout << "Do you have a coupon for this pruchase? (y or n)
\n";
cin >> response;
}
double findcheapest(double item1, item2, item3, item4)
{
if (((item1 <= item2) && (item1 <= item3) && (item1 <=
item4)))
{
lowest = item1;
}
if (((item2 <= item1) && (item2 <= item3) && (item2 <=
item4)))
{
lowest = item2;
}

if (((item3 <= item1) && (item3 <= item2) && (item3 <=
item4)))
{
lowest = item3;
}

if (((item4 <= item1) && (item4 <= item2) && (item4 <=
item3)))
{
lowest = item4;
}

}
void printresults(double response, double item1, double item2,
double item3, double item4, double total, double lowest);

{
cout << "Item 1 $" << setw(10) << item1 << endl;
cout << "Item 2 $" << setw(10) << item2 << endl;
cout << "Item 3 $" << setw(10) << item3 << endl;
cout << "Item 4 $" << setw(10) << item4 << endl;
cout << "Coupon Discount $(" << setw(10) <<
lowest<<")"<< endl;
cout << "----------------------------" << endl;
cout << "Total $" << setw(10) << total << endl;
}

}
"fourth.cpp" 84 lines, 2069 characters
$ g++ fourth.cpp -o fourth.out
fourth.cpp: In function `int main()':
fourth.cpp:13: implicit declaration of function `int instructions(...)'
fourth.cpp:14: implicit declaration of function `int get_item_price(...)'
fourth.cpp:20: implicit declaration of function `int getresponse(...)'
fourth.cpp: In function `void get_item_price()':
fourth.cpp:34: parse error before `<'
fourth.cpp:43: parse error before `{'
fourth.cpp:47: `response' undeclared (first use this function)
fourth.cpp:47: (Each undeclared identifier is reported only once
fourth.cpp:47: for each function it appears in.)
fourth.cpp: At top level:
fourth.cpp:49: type specifier omitted for parameter
fourth.cpp:49: type specifier omitted for parameter
fourth.cpp:49: type specifier omitted for parameter
fourth.cpp: In function `double findcheapest(double)':
fourth.cpp:51: `item2' undeclared (first use this function)
fourth.cpp:51: `item3' undeclared (first use this function)
fourth.cpp:51: `item4' undeclared (first use this function)
fourth.cpp:53: `lowest' undeclared (first use this function)
fourth.cpp: At top level:
fourth.cpp:74: parse error before `{'
fourth.cpp:76: syntax error before `<'
fourth.cpp:77: syntax error before `<'
fourth.cpp:78: syntax error before `<'
fourth.cpp:79: syntax error before `<'
fourth.cpp:80: syntax error before `<'
fourth.cpp:81: syntax error before `<'


and I can't figure out what to do<!!!.
Can anyone help out<?.
 
J

Jon Bell

int main()
{
double item1, item2, item3, item4, lowest=0, total;
char response;

instructions();
item1 = get_item_price();
item2 = get_item_price();
item3 = get_item_price();
item4 = get_item_price();
[snip]

It appears that main() expects get_item_price() to return a double as the
function value.

However, you've actually declared get_item_price() below as 'void', that
means it doesn't return a function value. Nor does the function have a
'return' statement that actually performs the return.
void get_item_price()

double get_item_price()
{
double i;

If a variable is supposed to contain a price, why not *name* it "price"?
:)
cout << "Enter the four item prices you want to buy.\n"
cout << "Item1: ";

Hmmm. In main(), you call this function four times, once for each price.
Do you really want to display the message above, four times?
cin >> i;
while (i<0)
{
cout << "Please enter a positive number: ";
cin >> i;
}

return i;
} // you're missing a curly brace, too.

I strongly urge you to get in the habit of indenting your code and
aligning your curly braces consistently. That makes it easier to spot
missing curly braces and some kinds of logic problems. There are a few
different ways of doing this, and some programmers love to argue about
which is the best way. Just study your textbook and copy the style that
it uses. Your instructor will surely appreciate it!

There are probably other mistakes, too, but I'll let others help you find
those.
 
S

Stephan Br?nnimann

tomakated said:
Hi, i'm new here and I can't get my get_item_price() function to work I
need it to take in 4 items

[code snipped]
"fourth.cpp" 84 lines, 2069 characters
$ g++ fourth.cpp -o fourth.out
fourth.cpp: In function `int main()':
fourth.cpp:13: implicit declaration of function `int instructions(...)'
fourth.cpp:14: implicit declaration of function `int get_item_price(...)'
fourth.cpp:20: implicit declaration of function `int getresponse(...)'
fourth.cpp: In function `void get_item_price()':
fourth.cpp:34: parse error before `<'
fourth.cpp:43: parse error before `{'
fourth.cpp:47: `response' undeclared (first use this function)
fourth.cpp:47: (Each undeclared identifier is reported only once
fourth.cpp:47: for each function it appears in.)
fourth.cpp: At top level:
fourth.cpp:49: type specifier omitted for parameter
fourth.cpp:49: type specifier omitted for parameter
fourth.cpp:49: type specifier omitted for parameter
fourth.cpp: In function `double findcheapest(double)':
fourth.cpp:51: `item2' undeclared (first use this function)
fourth.cpp:51: `item3' undeclared (first use this function)
fourth.cpp:51: `item4' undeclared (first use this function)
fourth.cpp:53: `lowest' undeclared (first use this function)
fourth.cpp: At top level:
fourth.cpp:74: parse error before `{'
fourth.cpp:76: syntax error before `<'
fourth.cpp:77: syntax error before `<'
fourth.cpp:78: syntax error before `<'
fourth.cpp:79: syntax error before `<'
fourth.cpp:80: syntax error before `<'
fourth.cpp:81: syntax error before `<'


and I can't figure out what to do<!!!.
Can anyone help out<?.

Fix the errors one by one. Remember that everything you are using
must be declared first.

BTW: consider using std::vector instead of the 4 doubles,
it might come in handy if you need to compare 1, 2, 3, 5, ... values.

Stephan Brönnimann
(e-mail address removed)
Open source rating and billing engine for communication networks.
 
T

tomakated

Not LIKING FUNCTIONS right now. Been at it for about 4 hours now..
What am I missing, I know it's right in front of me<?.

P.S. Have to work off main can't change it<!!!.

Now I get different errors......
fourth.cpp: In function `int main()':
fourth.cpp:13: implicit declaration of function `int instructions(...)'
fourth.cpp:14: implicit declaration of function `int get_item_price(...)'
fourth.cpp:20: implicit declaration of function `int getresponse(...)'
fourth.cpp: In function `int getresponse()':
fourth.cpp:48: parse error before `>'
fourth.cpp:51: `response' undeclared (first use this function)
fourth.cpp:51: (Each undeclared identifier is reported only once
fourth.cpp:51: for each function it appears in.)
fourth.cpp:54: parse error before `,'
fourth.cpp:55: `total' undeclared (first use this function)
fourth.cpp:55: `lowest' undeclared (first use this function)
fourth.cpp:62: type specifier omitted for parameter
fourth.cpp:62: type specifier omitted for parameter
fourth.cpp:62: type specifier omitted for parameter
fourth.cpp:64: parse error before `{'
fourth.cpp: At top level:
fourth.cpp:89: parse error before `{'
fourth.cpp:92: syntax error before `<'
fourth.cpp:93: syntax error before `<'
fourth.cpp:94: syntax error before `<'
fourth.cpp:95: syntax error before `<'
fourth.cpp:96: syntax error before `<'
fourth.cpp:97: syntax error before `<'


with this code....
#include <iostream>
#include <iomanip>

double findcheapest(double, double, double, double);
void printresults (double, double, double, double, double, double,
double);


int main()
{
double item1, item2, item3, item4, lowest=0, total;
char response;

instructions();
item1 = get_item_price();
item2 = get_item_price();
item3 = get_item_price();
item4 = get_item_price();
total = item1 + item2 + item3 + item4;
cout << "Do you have a coupon for this purchase? \n" ;
response = getresponse() ;
if (response == 'y')
{ lowest = findcheapest(item1, item2, item3,
item4);
total = total - lowest;
}
printresults (response, item1, item2, item3, item4,
total, lowest);
}


double get_item_price()
{
double i;
cout << "Enter the four item prices you want to buy.";
cout << "Item1: ";
cin >> i;
while (i<0)
{
cout << "Please enter a positive number: ";
cin >> i;
}

return i;
}

int getresponse()
{
cout << "Do you have a coupon for this purchase? (y or n):
\n"
cin >> response;


if ((response == 'y') || (response == 'Y'))

{
findcheapest(double item1, double item2, double item3,
double item4);
total = total - lowest;

if ((response == 'n') || (response == 'N'))
total = total;

}

double findcheapest(double item1, item2, item3, item4)

{
if (((item1 <= item2) && (item1 <= item3) && (item1 <=
item4)))
{
lowest = item1;
}
if (((item2 <= item1) && (item2 <= item3) && (item2 <=
item4)))
{
lowest = item2;
}

if (((item3 <= item1) && (item3 <= item2) && (item3 <=
item4)))
{
lowest = item3;
}

if (((item4 <= item1) && (item4 <= item2) && (item4 <=
item3)))
{
lowest = item4;
}

}

void printresults(double response, double item1, double item2,
double item3, double item4, double total, double lowest);

{

cout << "Item 1 $" << setw(10) << item1 << endl;
cout << "Item 2 $" << setw(10) << item2 << endl;
cout << "Item 3 $" << setw(10) << item3 << endl;
cout << "Item 4 $" << setw(10) << item4 << endl;
cout << "Coupon Discount $(" << setw(10) <<
lowest<<")"<< endl;
cout << "----------------------------" << endl;
cout << "Total $" << setw(10) << total << endl;
}
 
J

John Harrison

tomakated said:
Not LIKING FUNCTIONS right now. Been at it for about 4 hours now..
What am I missing, I know it's right in front of me<?.

P.S. Have to work off main can't change it<!!!.

Now I get different errors......
fourth.cpp: In function `int main()':
fourth.cpp:13: implicit declaration of function `int instructions(...)'

This is a lack of a prototype. You have prototypes for findcheapest and
printresults, you need them for all your functions.
fourth.cpp:14: implicit declaration of function `int get_item_price(...)'
Ditto

fourth.cpp:20: implicit declaration of function `int getresponse(...)'
Ditto

fourth.cpp: In function `int getresponse()':
fourth.cpp:48: parse error before `>'

This is mismatched curly brackets, as has already been explained to you by
Jon Bell. You need an extra } before the function get_item_price. The way to
avoid this sort of error is to INDENT YOUR CODE PROPERLY, as already stated
by Jon Bell.

Everything after here should be ignored until you fix these problems. Always
fix the first errors first, because the later errors might just be the
compiler getting confused by your earlier errors.

john
 
K

Karl Heinz Buchegger

tomakated said:
Not LIKING FUNCTIONS right now. Been at it for about 4 hours now..
What am I missing, I know it's right in front of me<?.

2 things:

* your code style is terrible. No wonder you can't see any errors in it.

* you made a typical newbie mistake: You wrote to much code in one big
rush and now unable to sort things out. Start small! Compile it, fix
any errors you have, then add new things.

Start eg with

int main()
{
}

compile it.
Then add things. But add *small* amounts of code

You could eg. continue with

int main()
{
double item1;

item1 = get_item_price();
cout << "You entered " << item1 << '\n';
}

double get_item_price()
{
return 0.0;
}

and make that compileable
(The above will already trigger the firt error in your program. The error
messages will be obvious and you should have no troubles fixing that)

Only then start to add the next thing. You could eg. add the inner workings
of get_item_price.

This way you usually will not be left with lots of error messages and don't
have an idea where the error could be. The error is always related to the
last code section you added. If you add only small amounts of code, you
only have to search in small code sections for errors.


PS: You can apply this scheme even now.
Save what you have right now into a new file (the backup). Remove everything
and start with a fresh, empty int main(). Then start copying things
from the backup into the new source code. But add small code sections
and recompile after each step. Do it in the spirit of above. Don't add
the complete main() from the backup. Just copy/paste enough from the
backup that you still have a complete main() which is compilable.
 
M

Michiel Salters

tomakated said:
Now I get different errors......
fourth.cpp: In function `int main()':
fourth.cpp:13: implicit declaration of function `int instructions(...)'
fourth.cpp:14: implicit declaration of function `int get_item_price(...)'
fourth.cpp:20: implicit declaration of function `int getresponse(...)'

You need to tell the compiler what these three functions look like.
main() calls them, so you must declare them before main. The 'int'
return type is just a guess by the compiler, so you might need to
change that.
fourth.cpp: In function `int getresponse()':
fourth.cpp:48: parse error before `>'

It's std::cout, std::cin, etcetera (if your compiler isn't obsolete)

Further errors occur because the compiler is lost.

HTH,
Michiel Salters
 
J

John Harrison

Karl Heinz Buchegger said:
2 things:

* your code style is terrible. No wonder you can't see any errors in it.

* you made a typical newbie mistake: You wrote to much code in one big
rush and now unable to sort things out. Start small! Compile it, fix
any errors you have, then add new things.

[more good advice snipped]

It's undoubtedly good advice, but have you ever known a newbie follow advice
like that? They have to learn the hard way.

OP, most programmers work like this, no matter how expert. The difference
when you get to be expert is that you add code in bigger chunks. As a newbie
you should add code in very small chunks and not be afraid to get to your
final goal gradually.

john
 
C

Carl Muller

tomakated said:
Not LIKING FUNCTIONS right now. Been at it for about 4 hours now..
What am I missing, I know it's right in front of me<?.

Learn to read the error messages the compiler is telling you.
P.S. Have to work off main can't change it<!!!.

Now I get different errors......
fourth.cpp: In function `int main()':
fourth.cpp:13: implicit declaration of function `int instructions(...)'
fourth.cpp:14: implicit declaration of function `int get_item_price(...)'
fourth.cpp:20: implicit declaration of function `int getresponse(...)'

These are warnings that you are using a function that you haven't
told the compiler about yet.
Look up "prototypes", or declare the functions before you use them.
For example you could put the main function at the bottom of the file.
fourth.cpp: In function `int getresponse()':
fourth.cpp:48: parse error before `>'

This is telling you to not forget the semicolon at the end of the cout line.
I would not pay much attention to subsequent error message until you fix that
one.
fourth.cpp:51: `response' undeclared (first use this function)
fourth.cpp:51: (Each undeclared identifier is reported only once
fourth.cpp:51: for each function it appears in.)
fourth.cpp:54: parse error before `,' [etc.]

int getresponse()
{
cout << "Do you have a coupon for this purchase? (y or n):
\n"
cin >> response;
 
V

velthuijsen

Now I get different errors......
fourth.cpp: In function `int main()':
fourth.cpp:13: implicit declaration of function `int instructions(...)'
fourth.cpp:14: implicit declaration of function `int get_item_price(...)'
fourth.cpp:20: implicit declaration of function `int getresponse(...)'
For these 3 do a declaration like findcheapest
The compiler can only work with what it knows exists, so you got to
tell it that yes there exists a function like getresponse and that you
are going to detail how it actually works later.
fourth.cpp: In function `int getresponse()':
fourth.cpp:48: parse error before `>'
fourth.cpp:51: `response' undeclared (first use this function)
fourth.cpp:51: (Each undeclared identifier is reported only once
fourth.cpp:51: for each function it appears in.)
fourth.cpp:54: parse error before `,'
fourth.cpp:55: `total' undeclared (first use this function)
fourth.cpp:55: `lowest' undeclared (first use this function)
fourth.cpp:62: type specifier omitted for parameter
fourth.cpp:62: type specifier omitted for parameter
fourth.cpp:62: type specifier omitted for parameter
fourth.cpp:64: parse error before `{'
fourth.cpp: At top level:
fourth.cpp:89: parse error before `{'
fourth.cpp:92: syntax error before `<'
fourth.cpp:93: syntax error before `<'
fourth.cpp:94: syntax error before `<'
fourth.cpp:95: syntax error before `<'
fourth.cpp:96: syntax error before `<'
fourth.cpp:97: syntax error before `<'

These are all errors because you got small things wrong, like :
Missing a ; or having a ; at the wrong place.
Forgetting that variables used in one function (this includes main)
are not necessarily known in other functions. Generally unless a
variable is declared global it only exists in the { } pair it is
declared in (there are quite a few exceptions to this but to get
started it'll do).
The use of type specfiers at the wrong place (in getresponse).

Question: Is this homework where you have to learn how to move parts
of the main to seperate functions?
 
K

Karl Heinz Buchegger

John said:
Karl Heinz Buchegger said:
2 things:

* your code style is terrible. No wonder you can't see any errors in it.

* you made a typical newbie mistake: You wrote to much code in one big
rush and now unable to sort things out. Start small! Compile it, fix
any errors you have, then add new things.

[more good advice snipped]

It's undoubtedly good advice, but have you ever known a newbie follow advice
like that?

:)
Sometimes I did, indeed.

(In the following substitute for X:
no proper indentation
writing to much in one rush
not choosing proper variable or function names
not splitting functionality into functions
....
)

First you tell them not to do X. Then they do X. Then you again
tell them to not do X. Then they say that in this specific case it
is
a) too late to not do X
b) they think they are very close to the solution, but in
the next project they will remember to not do X
c) for this 'simply project' X is an overkill

(choose a), b) or c) or all of them)

Then they spend a few additional hours to sort things out which are related
to doing X.

Then you take their hands and guide them through, showing them how not to do X
simplifies the process tremendously and by doing it that way they
a) get a better product
b) get the product in less time

Now repeat the whole process 2 or 3 times and suddenly they start to not do X
all by themselfs. :)
 
C

Carl Muller

tomakated said:
Not LIKING FUNCTIONS right now. Been at it for about 4 hours now..
What am I missing, I know it's right in front of me<?.

P.S. Have to work off main can't change it<!!!.

It looks like a student exercise in debugging! i.e. a task to spot how
many things are wrong with one piece of code. The obvious ones are:

1. Bad indenting hiding the structure
2. An assumption that all variables are global, and yet they are
declared local to main (actually this is just due to the next point):
3. Duplication of logic between two places
4. Completely missing function
5. Missing variable declaration
6. functions do not return values
7. Lack of prototypes
8. Extra semicolon
9. Missing semicolon
10. Extranneous types in function call
11. Missing types in function declarations
12. Lack of "using namespace std;" or "std::" everywhere
13. Code that doesn't do anything (total=total)
14. Poor algorithm choice, that does not scale easily
15. The prompt is misleading, it always says "item1"
 
T

tomakated

Still can't get it. I just want to be done with it. If anyone can help get
those errors gone that would be great.


P.S if you want to make the whole thing work for me that would be great
too. Been working on it for a week now<!!!!!.



#include <iostream>
#include <iomanip>

double findcheapest(double, double, double, double);
void printresults (double, double, double, double, double, double,
double);
void instructions();
double get_item_price();
int getresponse();
char response;
int lowest;
int total;

int main()
{
double item1, item2, item3, item4, lowest=0, total;
char response;

instructions();
item1 = get_item_price();
item2 = get_item_price();
item3 = get_item_price();
item4 = get_item_price();
total = item1 + item2 + item3 + item4;
cout << "Do you have a coupon for this purchase? \n" ;
response = getresponse() ;
if (response == 'y')
{ lowest = findcheapest(item1, item2, item3,
item4);
total = total - lowest;
}
printresults (response, item1, item2, item3, item4,
total, lowest);
}


double get_item_price()
{
double i;
cout << "Enter the four item prices you want to buy.";
cout << "Item1: ";
cin >> i;
while (i<0)
{
cout << "Please enter a positive number: ";
cin >> i;
}

return i;
}

int getresponse()
{
cout << "Do you have a coupon for this purchase? (y or n):
\n";
cin >> response;

if ((response == 'y') || (response == 'Y'))
{
lowest = findcheapest(double item1, double item2, double
item3, double item4);
total = total - lowest;

if ((response == 'n') || (response == 'N'))
total = total;

}

double findcheapest(double item1, double item2, double item3,
double item4)

{
if (((item1 <= item2) && (item1 <= item3) && (item1 <=
item4)))
{
lowest = item1;
}
if (((item2 <= item1) && (item2 <= item3) && (item2 <=
item4)))
{
lowest = item2;
}

if (((item3 <= item1) && (item3 <= item2) && (item3 <=
item4)))
{
lowest = item3;
}

if (((item4 <= item1) && (item4 <= item2) && (item4 <=
item3)))
{
lowest = item4;
}

}

void printresults(double response, double item1, double item2,
double item3, double item4, double total, double lowest)

{

cout << "Item 1 $" << setw(10) << item1 << endl;
cout << "Item 2 $" << setw(10) << item2 << endl;
cout << "Item 3 $" << setw(10) << item3 << endl;
cout << "Item 4 $" << setw(10) << item4 << endl;
cout << "Coupon Discount $(" << setw(10) <<
lowest<<")"<< endl;
cout << "----------------------------" << endl;
cout << "Total $" << setw(10) << total << endl;
}

"fourth.cpp" 102 lines, 2384 characters
$ g++ fourth.cpp -o fourth.out
fourth.cpp: In function `int getresponse()':
fourth.cpp:57: parse error before `,'
fourth.cpp:67: parse error before `{'
 
O

osmium

tomakated said:
Still can't get it. I just want to be done with it. If anyone can help get
those errors gone that would be great.


P.S if you want to make the whole thing work for me that would be great
too. Been working on it for a week now<!!!!!.



#include <iostream>
#include <iomanip>

double findcheapest(double, double, double, double);
void printresults (double, double, double, double, double, double,
double);
void instructions();
double get_item_price();
int getresponse();
char response;
int lowest;
int total;

int main()
{
double item1, item2, item3, item4, lowest=0, total;
char response;

instructions();
item1 = get_item_price();
item2 = get_item_price();
item3 = get_item_price();
item4 = get_item_price();
total = item1 + item2 + item3 + item4;
cout << "Do you have a coupon for this purchase? \n" ;
response = getresponse() ;
if (response == 'y')
{ lowest = findcheapest(item1, item2, item3,
item4);
total = total - lowest;
}
printresults (response, item1, item2, item3, item4,
total, lowest);
}


double get_item_price()
{
double i;
cout << "Enter the four item prices you want to buy.";
cout << "Item1: ";
cin >> i;
while (i<0)
{
cout << "Please enter a positive number: ";
cin >> i;
}

return i;
}

int getresponse()
{
cout << "Do you have a coupon for this purchase? (y or n):
\n";
cin >> response;

if ((response == 'y') || (response == 'Y'))
{
lowest = findcheapest(double item1, double item2, double
item3, double item4);

Take all those "double" out of there. This is a call of a function, not a
definition.

<snip>
 
S

Stephan Br?nnimann

tomakated said:
Still can't get it. I just want to be done with it. If anyone can help get
those errors gone that would be great.


P.S if you want to make the whole thing work for me that would be great
too. Been working on it for a week now<!!!!!.



#include <iostream>
#include <iomanip>

double findcheapest(double, double, double, double);
void printresults (double, double, double, double, double, double,
double);
void instructions();
double get_item_price();
int getresponse();
char response;
int lowest;
int total;

int main()
{
double item1, item2, item3, item4, lowest=0, total;
char response;

instructions();
item1 = get_item_price();
item2 = get_item_price();
item3 = get_item_price();
item4 = get_item_price();
total = item1 + item2 + item3 + item4;
cout << "Do you have a coupon for this purchase? \n" ;
response = getresponse() ;
if (response == 'y')
{ lowest = findcheapest(item1, item2, item3,
item4);
total = total - lowest;
}
printresults (response, item1, item2, item3, item4,
total, lowest);
}


double get_item_price()
{
double i;
cout << "Enter the four item prices you want to buy.";
cout << "Item1: ";
cin >> i;
while (i<0)
{
cout << "Please enter a positive number: ";
cin >> i;
}

return i;
}

int getresponse()
{
cout << "Do you have a coupon for this purchase? (y or n):
\n";
cin >> response;

if ((response == 'y') || (response == 'Y'))
{
lowest = findcheapest(double item1, double item2, double
item3, double item4);
total = total - lowest;

if ((response == 'n') || (response == 'N'))
total = total;

}

double findcheapest(double item1, double item2, double item3,
double item4)

{
if (((item1 <= item2) && (item1 <= item3) && (item1 <=
item4)))
{
lowest = item1;
}
if (((item2 <= item1) && (item2 <= item3) && (item2 <=
item4)))
{
lowest = item2;
}

if (((item3 <= item1) && (item3 <= item2) && (item3 <=
item4)))
{
lowest = item3;
}

if (((item4 <= item1) && (item4 <= item2) && (item4 <=
item3)))
{
lowest = item4;
}

}

void printresults(double response, double item1, double item2,
double item3, double item4, double total, double lowest)

{

cout << "Item 1 $" << setw(10) << item1 << endl;
cout << "Item 2 $" << setw(10) << item2 << endl;
cout << "Item 3 $" << setw(10) << item3 << endl;
cout << "Item 4 $" << setw(10) << item4 << endl;
cout << "Coupon Discount $(" << setw(10) <<
lowest<<")"<< endl;
cout << "----------------------------" << endl;
cout << "Total $" << setw(10) << total << endl;
}

"fourth.cpp" 102 lines, 2384 characters
$ g++ fourth.cpp -o fourth.out
fourth.cpp: In function `int getresponse()':
fourth.cpp:57: parse error before `,'
fourth.cpp:67: parse error before `{'

Hint 1: use proper indentation and the origin of your problems
will show up as if by a miracle.
Hint 2: try to compile in the editor that you are using, e.g. for vim:
vi fourth.cpp
make fourth

regards
Stephan Brönnimann
(e-mail address removed)
Open source rating and billing engine for communication networks.
 
A

Adam

You haven't got a "}" at the end of your getresponse() function.
Put one in before double findcheapest(...).
 
V

velthuijsen

FYI even fixing the two errors would not fix the program in such a way
that it would give a meaningful result.
IMHO you might best start over with building this program. And start
by defining what each function needs to do and what that function
needs to be able to do that.
fourth.cpp:57: parse error before `,'
Not strange that you get this error there.
take a good look at the following two lines:
lowest = findcheapest(double item1, double item2, double item3, double
item4);
lowest = findcheapest(item1, item2, item3, item4);

The first line is the one in getresponse() that the compiler complains
about
The second line is the one in main.
fourth.cpp:67: parse error before `{'

You forgot a } earlier (the one to close getresponse() ). If the post
hasn't mangled the spacing in your program you might really want to
consider a way of lining out that gives a better indication of that
one is forgotten or when ever you write a { write the corresponding }
directly or something like that to reduce that kind of mistake.

When you fix this you should still have a few problems left.
If your compiler is worth anything at least two errors or warnings in
which the compiler complains about not getting return values for
findcheapest and getresponse.
Most likely a linker error since you've defined
instructions();
but never give a body that comes with the function.

And some more subtle problems that might or might not generate
warnings.
The warnings will probably be of the type
"Trying to convert double to int"
"Using local variable without initialization"

The subtle problems are based on
The fact that functions (generally) do not know the values stored in
variables of other functions (main is just a function).
Forgetting to declare the type of variables.

Also you might want to give getresponse() the values it needs to give
to findcheapest().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top