| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Can anyone get the errors to go away for me, been trying for a week now. I am new to the programming world as you might tell from the format of it.
Thanks, tomakated@comcast.net any help that can be given that would be great< !!!. #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 `{' $ lowest = findcheapest(double item1, double item2, double item3, double item4); lowest = findcheapest(double item1, double item2, double item3, double item4); double findcheapest(double item1, double item2, double item3, double item4) { ![]() |
|
#2
|
|||
|
|||
|
hi frnd,
1. The first error you have specified is "Parse Error before ," in lowest = findcheapest(double item1, double item2, double item3, double item4); This is where you call the function "findcheapest" .while calling the function you should not specify the data type.(here double).so after modification lowest = findcheapest(item1, item2, item3, item4); and in the function findcheapest you have not used return statements. check that also. 2. Parse Error In fuction int getresponse() b'coz you have not closed the braces"}" . so do that. mail me for more details. I guess this may help you. with Regards aarthy. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Two Errors in my functions that can't figure them out |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|