Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 03-01-09   #1 (permalink)
New to Overclock.net
 
YeaBaby's Avatar
 
amd ati

Join Date: Dec 2005
Location: Knoxville, TN.
Posts: 966

Rep: 69 YeaBaby is acknowledged by some
Unique Rep: 61
Trader Rating: 17
Default Another "I need help" with C++ thread (please help)

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

System: A Computer
CPU
Unlocked X3 710
Motherboard
Gigabyte 790 GX
Memory
6 gigs of G. Skill Pi and Crucial Ballistix mixed
Graphics Card
XFX 4850 1 gig version
Hard Drive
5 x Seagate Sata II -1.64 TB total
Sound Card
Onboard Realtek
Power Supply
Antec NeoPower 650 watt
Case
Antec 900
CPU cooling
Xigmatek S-1283
GPU cooling
stock
OS
Dual Boot Vista Ultimate 64 bit + Windows 7 Beta
Monitor
Hanns G 22" LCD

Last edited by YeaBaby : 03-31-09 at 12:19 AM
YeaBaby is offline   Reply With Quote
Old 03-01-09   #2 (permalink)
New to Overclock.net
 
YeaBaby's Avatar
 
amd ati

Join Date: Dec 2005
Location: Knoxville, TN.
Posts: 966

Rep: 69 YeaBaby is acknowledged by some
Unique Rep: 61
Trader Rating: 17
Default

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

System: A Computer
CPU
Unlocked X3 710
Motherboard
Gigabyte 790 GX
Memory
6 gigs of G. Skill Pi and Crucial Ballistix mixed
Graphics Card
XFX 4850 1 gig version
Hard Drive
5 x Seagate Sata II -1.64 TB total
Sound Card
Onboard Realtek
Power Supply
Antec NeoPower 650 watt
Case
Antec 900
CPU cooling
Xigmatek S-1283
GPU cooling
stock
OS
Dual Boot Vista Ultimate 64 bit + Windows 7 Beta
Monitor
Hanns G 22" LCD
YeaBaby is offline   Reply With Quote
Old 03-01-09   #3 (permalink)
With great difficulty
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 5,210

Rep: 614 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 370
FAQs Submitted: 6
Trader Rating: 5
Default

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?
__________________
System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 03-03-09   #4 (permalink)
Programmer
 
intel ati

Join Date: Aug 2006
Location: Moscow, ID
Posts: 173

Rep: 12 Safetydan Unknown
Unique Rep: 11
Trader Rating: 1
Default

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

System: Monster v2
CPU
Q6600 G0
Motherboard
GA-P35-DS3L
Memory
2GB Crucial Ballistix
Graphics Card
Saphire Radeon x1900XTX
Hard Drive
WD 320GB
Sound Card
x-fi extreme music (modded)
Power Supply
OCZ 700W
Case
Gigabyte 3D aurora
CPU cooling
TR Ultra-120 Extreme
GPU cooling
vf900
OS
Windows XP
Monitor
2x Acer 22" WS
Safetydan is offline   Reply With Quote
Reply

Tags
c++, c++ help, programming


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 12:53 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.13541 seconds with 8 queries