Arrays 1

hi the teacher has asked us to embed the code in the algorithm he wrote... im not really sure what im doing but here it is...what should i do different?.. thank you so much
// Start
#include <iostream>
#include <cstdlib>
using namespace std;
int main( )
{

// Declarations
// num SIZE = 5
Const int SIZE = 5;
// num COFFEEPRICE = 2.00
Int COFFEEPRICE = 2.00;
// string products[SIZE]="Whipped cream", "Cinnamon", "Chocolate sauce", "Amaretto", ""Irish whiskey"
Const string[SIZE]={“Whipped cream”, “Cinnamon”, “Chocolate sauce”, “Amaretto”, “Irish whiskey”}
// num prices[SIZE]=0.89, 0.25, 0.59, 1.50, 1.75
double prices[SIZE]={0.89, 0.25, 0.59, 1.5, 1.75};
// num totalPrice = 0
Int totalPrice=0;
// num choice = 0
Int choice=0;
// num SENTINEL = -1
Int SENTINEL=-1;
//
// while (choice <> SENTINEL))
While(choice <> SENTINEL))
{
// output "Please select an item from the Product menu by selecting the item number (1 - 5) or -1 to terminate: "
Cout<<”Please select an item from the Product menu by selecting the item number (1-5)or -1 to terminate: “<<item<<endl;
// output "Product Price ($)"
Cout<<”Product Price ($)”<<price<<endl;
// output "======= ========="
Cout<<”output “====== ========” Price ($)”<= =<<endl;

// output "1. Whipped cream 0.89"
Cout<<”Whipped cream 0.89”<<whippedCream<<endl;

// output "2. Cinnamon 0.25"
Cout<<”Cinnamon 0.25”<<Cinnamon<<endl;

// output "3. Chocolate sauce 0.89"
Cout<<”Chocolate sauce 0.89”<<chocolateSauce<<endl;

// output "4. Amaretto 1.50"
Cout<<”Amaretto 1.5”<<Amaretto<<endl;

// output "5. Irish whiskey 1.75"
Cout<<”Irish Whiskey 1.75”<<irishWhiskey<<endl;

// output "Please enter a positive number: "
Cout<<”Please enter a positive number: “<<positiveNumber<<endl;

// input choice
Cin>>positive number;
// if (choice <> SENTINEL) then
If (choice <> SENTINEL) then
}

// if ((choice >= 1) and (choice <= 5)) then
If ((choice >= 1)&&(choice<=5)) then
// totalPrice = totalPrice + prices[choice-1]
totalPrice=totalPrice + prices[choice-1]
}
// output "Item number ", choice,": ", products[choice-1], " has been added"
Cout<<"Item number ", choice,": ", products[choice-1], " has been added"
<<itemNumber<<endl;

// else
{

// output "Item number ",choice, " is not valid", "Sorry we do not carry that item"
Cout<<"Item number ",choice, " is not valid", "Sorry we do not carry that item"

<<itemNumberNotValid<<endl;
}
}

// endif
// endif
// endwhile
// totalPrice = totalPrice + COFFEEPRICE
totalPrice = toyalPrice+ COFFEEPRICE;
// output "Total price of order is ",totalPrice
Cout<<"Total price of order is ",totalPrice<<totalPrice<<endl;

// output "Thanks for purchasing from Jumpin Jive Coffee Shop"
Cout<<"Thanks for purchasing from Jumpin Jive Coffee Shop"<<thanks<<endl;

// Stop
system(“PAUSE”);
return 0;
}


Please use code tags for your code, this makes it much more readable for everyone.

From what I can see there are a lot of errors, here are just some of them:

Variable data types have a capital letter, i.e. Const and Int which should be const and int - Visual Studio would complain about this, not 100% sure if some free compilers would let this pass regardless (someone correct me) - I'm guessing you have added code in a word processor or something as it looks like its capitalised each instruction such as cout, cin, if etc.

You have a lot of missing semicolons ; which terminate a instruction or declaration.

You have declared COFFEEPRICE as a integer, yet initialised it as a floating point number 2.00.

Same again with totalPrice, the calculations would be against doubles yet you have declared this as an int.

The While loop doesn't have a capital W, should be while - again, please someone correct me if other compilers are less fussy.

There are bits of pascal in there, i.e. <> which is pascal for not equal to

Throughout your code you are using instead of "


Anyway, that's what I picked up on when reading your post, and I may have missed many others.
closed account (j3Rz8vqX)
Looks like a sloppy/quick copy. You should consider cleaning it up; more.

Tip:
Use a loop to print values from your products array and prices array.
Also, some of the commas should be << at least those being outputed.
Judging by the incorrect capitalisation of keywords such as Const and Int, as well as the use of non-ASCII quotes, I'd make a guess that a word-processor was used to type this.

So first advice, use a proper text editor, preferably one designed for editing code. For example Notepad++ if you're using Windows, though everyone has their own favourite. http://notepad-plus-plus.org/
Topic archived. No new replies allowed.