473,507 Members | 6,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get_item_price

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<?.

Jul 22 '05 #1
18 1765
In article <b7******************************@localhost.talkab outprogramming.com>,
tomakated <to*******@comcast.net> wrote:

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.

--
Jon Bell <jt*******@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
Jul 22 '05 #2
"tomakated" <to*******@comcast.net> wrote in message news:<b7******************************@localhost.t alkaboutprogramming.com>...
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
br****@osb-systems.com
Open source rating and billing engine for communication networks.
Jul 22 '05 #3
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;
}
Jul 22 '05 #4

"tomakated" <to*******@comcast.net> wrote in message
news:69******************************@localhost.ta lkaboutprogramming.com...
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
Jul 22 '05 #5
tomakated wrote:

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.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #6
"tomakated" <to*******@comcast.net> wrote in message news:<69******************************@localhost.t alkaboutprogramming.com>...
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
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;
}

Jul 22 '05 #7

"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:41***************@gascad.at...
tomakated wrote:

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.


[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
Jul 22 '05 #8
"tomakated" <to*******@comcast.net> wrote in message news:<69******************************@localhost.t alkaboutprogramming.com>...
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;

Jul 22 '05 #9
> 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?
Jul 22 '05 #10
John Harrison wrote:

"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:41***************@gascad.at...
tomakated wrote:

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.


[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. :-)

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #11
"tomakated" <to*******@comcast.net> wrote in message news:<69******************************@localhost.t alkaboutprogramming.com>...
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"
Jul 22 '05 #12
Thanks for all your Help<!!!.

I will try that small amount of code at a time

Jul 22 '05 #13
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 `{'

Jul 22 '05 #14
"tomakated" writes:
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>
Jul 22 '05 #15
"tomakated" <to*******@comcast.net> wrote in message news:<cf******************************@localhost.t alkaboutprogramming.com>...
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
br****@osb-systems.com
Open source rating and billing engine for communication networks.
Jul 22 '05 #16
You haven't got a "}" at the end of your getresponse() function.
Put one in before double findcheapest(...).
Jul 22 '05 #17
Count your braces around the if... =)

-dave-
"tomakated" <to*******@comcast.net> wrote in message news:<cf******************************@localhost.t alkaboutprogramming.com>...
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<!!!!!.


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)

[...]
"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 `{'

Jul 22 '05 #18
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().
Jul 22 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1030
by: Joe | last post by:
Can someone look at this code and tell me why I can not read in the input characters. //Invoice.hpp file #include <iostream> #include <string.h> using namespace std;
14
2091
by: B Williams | last post by:
I am stuck on an assignment that uses classes and functions. I am receiving numerous errors when I try to run a test program to see if I wrote it correctly. Can someone please point me in the right...
2
3964
by: zaidalin79 | last post by:
Here is my Inventory program for my Java class.... //Inventory.java //Class created to store item information for Inventory purposes //Created November 15, 2006 //Modified November 29, 2006...
5
2131
by: zaidalin79 | last post by:
Please-if anyone is online that can help me with a couple beginner Java programs... I have spent all day looking at them and I just can't figure out what I need to do... Please help!!
2
2882
by: zaidalin79 | last post by:
r03581x has been helping me with a program, but he won't be online till Monday, and I have to have this finished by tomorrow... Is there anyone else out there that can help me? Here is the first...
67
22896
by: hollywoood | last post by:
I am trying to add the Delete button, save and search buttons. I have tried to call my teacher and he is absolutly no help and i have read and reread the text but still have no idea what is going...
5
3361
by: cblank | last post by:
I'm having some trouble with my inventory program. Its due tom and my teacher is not wanting to help. He keeps giving me a soluction that is not related to my code. I have everything working except...
2
1417
by: DonE | last post by:
Help me please. I am having problems with my homework assignment. We are to create a product class that hold the item number, the name of the product, the number of units in stock, and the price of...
1
2648
by: jcato77 | last post by:
I need help with a class project I'm working on, Below is my assignment and the code I have currently created. Assignment: Modify the Inventory Program by creating a subclass of the product class...
13
2060
by: jcato77 | last post by:
I am having trouble figuring out my code and was hoping someone could point me in the right direction. Below is my code what I need to due is create a method to add and display the value of the...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.