|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
Another "I need help" with C++ thread (please help)
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
New to Overclock.net
![]() |
Ok guys need a little help here please.
I am using Visual Studio to write my code however I am compiling the code and running it in the Unix Secure Shell environment. I have managed to get this program down to just 3 errors but my brain is fried and I know I'm missing some simple silly error that I have made. I have attached screens of the code itself and also a screen of the error messages I'm getting in Unix. Any help will be greatly appreciated. Thanks Yeababy /* Author: UserId #: c1020a20 Creation Date: 02/22/2009 Modification Date: 02/24/2009 Course: CSIT 1020P01 – Spring, 2009 File name: Strawberries.cpp Inputs: Ouputs: Formulas: Purpose: Write a program for Fancy Fruits that will allow a sales associate to input the amount and type of strawberries a customer wants to order and calculate a final sales price plus tax. */ #include <iostream> using namespace std; int main() { const double oneDozenPlainStrawberries = 6.50; const double twoDozenPlainStrawberries = 15.50; const double oneDozenChocolateStrawberries = 12.50; const double twoDozenChocolateStrawberries = 20.00; double preTaxPrice = 0.00; double finalPrice = 0.00; char typeOfStrawberries; int numberOfStrawberries; char loopAgain; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << "Fancy Fruits is pleased to provide you with giant strawberries today. "; cout << "Your sales associate will be Joseph Vaughn. "; cout << "Would you like to order 1 dozen or 2 dozen strawberries? "; cin >> numberOfStrawberries; cout << "Would you like plain, milk, white, or dark dipped chocolate strawberries (P, M, W, D)? "; cin >> typeOfStrawberries; while (loopAgain == 'Y' || loopAgain =='y') switch (typeOfStrawberries) { case 'P': case 'p': if (numberOfStrawberries == 1) preTaxPrice = oneDozenPlainStrawberries; else if (numberOfStrawberries == 2) preTaxPrice = twoDozenPlainStrawberries; break; case 'M': case 'm': if (numberOfStrawberries == 1) preTaxPrice = oneDozenChocolateStrawberries; else if (numberOfStrawberries == 2) preTaxPrice = twoDozenChocolateStrawberries; break; case 'W': case 'w': if (numberOfStrawberries == 1) preTaxPrice = oneDozenChocolateStrawberries; else if (numberOfStrawberries == 2) preTaxPrice = twoDozenChocolateStrawberries; break; case 'D': case 'd': if (numberOfStrawberries == 1) preTaxPrice = oneDozenChocolateStrawberries; else if (numberOfStrawberries == 2) preTaxPrice = twoDozenChocolateStrawberries; break; cout << "The total before tax for your order of strawberries is " << preTaxPrice; cout << "Would like another order of strawberries ('Y' or 'N')? "; if (loopAgain = 'Y' || 'y') cin >> loopAgain } return 0; } What I'm getting as far as compiling errors. Sun Mar 1 21:36:39 EST 2009 > pwd /export/home/students/c1020a/c1020a20 > cd csit1020 > ls Strawberries.cpp calories2a lab1b.txt runcalories calories.cpp calories2a.cpp p1.cpp runcalories2 calories2.cpp calories2a.txt p2.cpp > g++ Strawberries.cpp -o straw Strawberries.cpp: In function `int main()': Strawberries.cpp:113: error: expected `;' before '}' token Strawberries.cpp:147:2: warning: no newline at end of file >
__________________
Hug a fanboy today
Last edited by YeaBaby : 03-31-09 at 12:19 AM |
|||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
New to Overclock.net
![]() |
An update here. Adding a ; after cin >> loopagain made a big difference duh! The program will compile now but I am not able to get past:
cout << "Would you like plain, milk, white, or dark dipped chocolate strawberries (P, M, W, D)? "; cin >> typeOfStrawberries;
__________________
Hug a fanboy today
|
|||||||||||||
|
|
|
|
|
#3 (permalink) | |||||||||||||
|
With great difficulty
![]() |
Please put any code in [code] tags. It keeps the spacing and uses monospace text which makes it much easier to read. Also, what do you mean you can't get past that part? Does the program crash? Does it hang? What problem are you having?
__________________
|
|||||||||||||
|
|
|
|
#4 (permalink) | |||||||||||||
|
Programmer
|
You were missing an initialization on your "loopAgain" variable, that would have caused you never to enter your main loop there. You also had an un-needed if(loopAgain == 'Y') statement in there.
You did not have an opening curly brace for your while loop. You did not have a closing curly brace for your switch statement. Also, if you want the preTaxPrice to get added to with each loop (every time the user adds another order) you need to change all those "preTaxPrice = " to "preTaxPrice += ". That's all I saw when reading over it, I didn't try to compile or run it. Hope that helps. ![]() Code with changes bolded Code:
#include <iostream>
using namespace std;
int main()
{
const double oneDozenPlainStrawberries = 6.50;
const double twoDozenPlainStrawberries = 15.50;
const double oneDozenChocolateStrawberries = 12.50;
const double twoDozenChocolateStrawberries = 20.00;
double preTaxPrice = 0.00;
double finalPrice = 0.00;
char typeOfStrawberries;
int numberOfStrawberries;
char loopAgain = 'Y';
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "Fancy Fruits is pleased to provide you with giant strawberries today. ";
cout << "Your sales associate will be Joseph Vaughn. ";
cout << "Would you like to order 1 dozen or 2 dozen strawberries? ";
cin >> numberOfStrawberries;
cout << "Would you like plain, milk, white, or dark dipped chocolate strawberries (P, M, W, D)? ";
cin >> typeOfStrawberries;
while (loopAgain == 'Y' || loopAgain =='y')
{
switch (typeOfStrawberries)
{
case 'P': case 'p':
if (numberOfStrawberries == 1)
preTaxPrice = oneDozenPlainStrawberries;
else if (numberOfStrawberries == 2)
preTaxPrice = twoDozenPlainStrawberries;
break;
case 'M': case 'm':
if (numberOfStrawberries == 1)
preTaxPrice = oneDozenChocolateStrawberries;
else if (numberOfStrawberries == 2)
preTaxPrice = twoDozenChocolateStrawberries;
break;
case 'W': case 'w':
if (numberOfStrawberries == 1)
preTaxPrice = oneDozenChocolateStrawberries;
else if (numberOfStrawberries == 2)
preTaxPrice = twoDozenChocolateStrawberries;
break;
case 'D': case 'd':
if (numberOfStrawberries == 1)
preTaxPrice = oneDozenChocolateStrawberries;
else if (numberOfStrawberries == 2)
preTaxPrice = twoDozenChocolateStrawberries;
break;
}
cout << "The total before tax for your order of strawberries is " << preTaxPrice;
cout << "Would like another order of strawberries ('Y' or 'N')? ";
cin >> loopAgain
}
return 0;
}
__________________
"He attacked everything in life with a mix of extraordinary genius and naive incompetence, and it was often difficult to tell which was which." Douglas Adams
|
|||||||||||||
|
|
|
![]() |
| Tags |
| c++, c++ help, programming |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|