Never mind. I finally figured it out.
KittyGirl 0 Newbie Poster
Well, I got the 'for' statement correct, but it still isn't printing a list of choices or adding the amounts. Should I put an 'if' statement in there? Please advise. This is due tonight.
Thanks!
Here's the most recent code that I've done.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int noOfItems = 8;
struct menuItemType
{
string menuItem;
double menuPrice;
};
void getData(ifstream& inFile, menuItemType mList[], int listSize);
void showMenu(menuItemType mList[], int listSize);
void printCheck(menuItemType mList[], int listSize,
int cList[], int cListLength);
void makeSelection(menuItemType mList[], int listSize,
int cList[], int& cListLength);
bool isItemSelected(int cList[], int cListLength, int itemNo);
int main()
{
menuItemType menuList[noOfItems];
int choiceList[noOfItems];
int choiceListLength;
ifstream inFile;
cout << fixed << showpoint << setprecision(2);
inFile.open("Ch12_Ex3Data.txt");
if (!inFile)
{
cout << "Cannot open the input file. Program Terminates!"
<< endl;
return 1;
}
getData (inFile, menuList, noOfItems);
showMenu(menuList, noOfItems);
makeSelection(menuList, noOfItems, choiceList, choiceListLength);
printCheck(menuList, noOfItems, choiceList, noOfItems);
return 0;
}
void getData(ifstream& inFile, menuItemType mList[], int listSize)
{
char ch;
for (int i = 0; i < listSize; i++)
{
getline(inFile, mList[i].menuItem);
inFile >> mList[i].menuPrice;
inFile.get(ch);
}
}
void showMenu(menuItemType mList[], int listSize)
{
cout << "Welcome to Johnny's Restaurant" << endl;
cout << "----Today's Menu----" << endl;
for (int i = 0; i < listSize; i++)
cout<<left<<setw(15)<<mList[i].menuItem<<right<<mList[i].menuPrice<<endl;
cout<<endl;
}
void printCheck(menuItemType mList[], int listSize,
int cList[], int cListLength)
{
int i;
double salesTax;
double amountDue = 0;
cout << "Welcome to Johnny's Restaurant" << endl;
for (i = 0; …
KittyGirl 0 Newbie Poster
OK, I finally got it to print out in the tabular format, but I still can't get it to add the amounts. I've tried a few different things, but I think my for loop may be wrong. Can someone help, please?
Thanks!
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int noOfItems = 8;
struct menuItemType
{
string menuItem;
double menuPrice;
};
void getData(ifstream& inFile, menuItemType mList[], int listSize);
void showMenu(menuItemType mList[], int listSize);
void printCheck(menuItemType mList[], int listSize,
int cList[], int cListLength);
void makeSelection(menuItemType mList[], int listSize,
int cList[], int& cListLength);
bool isItemSelected(int cList[], int cListLength, int itemNo);
int main()
{
menuItemType menuList[noOfItems];
int choiceList[noOfItems];
int choiceListLength;
ifstream inFile;
cout << fixed << showpoint << setprecision(2);
inFile.open("Ch11_Ex3Data.txt");
if (!inFile)
{
cout << "Cannot open the input file. Program Terminates!"
<< endl;
return 1;
}
getData (inFile, menuList, noOfItems);
showMenu(menuList, noOfItems);
makeSelection(menuList, noOfItems, choiceList, choiceListLength);
printCheck(menuList, noOfItems, choiceList, noOfItems);
return 0;
}
void getData(ifstream& inFile, menuItemType mList[], int listSize)
{
char ch;
for (int i = 0; i < listSize; i++)
{
getline(inFile, mList[i].menuItem);
inFile >> mList[i].menuPrice;
inFile.get(ch);
}
}
void showMenu(menuItemType mList[], int listSize)
{
cout << "Welcome to Johnny's Resturant" << endl;
cout << "----Today's Menu----" << endl;
for (int i = 0; i < listSize; i++)
cout<<left<<setw(15)<<mList[i].menuItem<<right<<mList[i].menuPrice<<endl;
cout<<endl;
}
void printCheck(menuItemType mList[], int listSize,
int cList[], int cListLength)
{
int i;
double salesTax;
double amountDue = 0;
cout << "Welcome to Johnny's Resturant" << endl;
for (i = 0; i < …
KittyGirl 0 Newbie Poster
OK, here's my problem. This is supposed to print out a list of menu items. You choose from the list, then print the bill. My problem is that I can't seem to get the menu items to print out in a tabular format and my printout won't add the items together. I keep getting zeros for the tax and amount due. Any help is greatly appreciated.
Thanks!
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int noOfItems = 8;
struct menuItemType
{
string menuItem;
double menuPrice;
};
void getData(ifstream& inFile, menuItemType mList[], int listSize);
void showMenu(menuItemType mList[], int listSize);
void printCheck(menuItemType mList[], int listSize,
int cList[], int cListLength);
void makeSelection(menuItemType mList[], int listSize,
int cList[], int& cListLength);
bool isItemSelected(int cList[], int cListLength, int itemNo);
int main()
{
menuItemType menuList[noOfItems];
int choiceList[noOfItems];
int choiceListLength;
ifstream inFile;
cout << fixed << showpoint << setprecision(2);
inFile.open("Ch11_Ex3Data.txt");
if (!inFile)
{
cout << "Cannot open the input file. Program Terminates!"
<< endl;
return 1;
}
getData (inFile, menuList, noOfItems);
showMenu(menuList, noOfItems);
makeSelection(menuList, noOfItems, choiceList, choiceListLength);
printCheck(menuList, noOfItems, choiceList, noOfItems);
return 0;
}
void getData(ifstream& inFile, menuItemType mList[], int listSize)
{
char ch;
for (int i = 0; i < listSize; i++)
{
getline(inFile, mList[i].menuItem);
inFile >> mList[i].menuPrice;
inFile.get(ch);
}
}
void showMenu(menuItemType mList[], int listSize)
{
cout << "Welcome to Johnny's Resturant" << endl;
cout << "----Today's Menu----" << endl;
for (int i = 0; i < listSize; i++)
{
cout<<mList[i].menuItem<<setw(15)<<mList[i].menuPrice;
}
}
void printCheck(menuItemType mList[], int listSize,
int …
KittyGirl 0 Newbie Poster
I'm writing a program that asks the user to input 3 numbers, then outputs the shape of the triangle. This is what I have so far, but it still doesn't work.
Can someone help?
Thanks!
#include <iostream>
using namespace std;
enum triangleType {scalene, isosceles, equilateral, noTriangle};
void triangleShape (int shape);
int main()
{
float A, B, C;
int shape;
cout<<"Enter the length of three sides of a triangle"<<endl;
cin>>A;
cin>>B;
cin>>C;
triangleShape (shape);
if (shape == equilateral)
cout<<"The shape of the triangle is: equilateral";
else if (shape == isosceles)
cout<<"The shape of the triangle is: isosceles";
else if (shape == scalene)
cout<<"The shape of the triangle is: scalene";
else
cout<<"The shape of the triangle is: noTriangle";
cout<<endl;
return 0;
}
void triangleShape (int shape) //my instructor said to make shape of
//type triangleShape, but I'm not sure
//what that means, plz explain
{
int A, B, C;
int shape;
if ((A == B)&&(B == C))
shape = equilateral;
else if ((A == B)||(B == C)||(A == C))
shape = isosceles;
else if ((A != B)||(B != C)||(A != C))
shape = scalene;
else
shape = noTriangle;
}
KittyGirl 0 Newbie Poster
Thank you so much! This worked beautifully.
I'm fairly new to this stuff, so I usually ask a lot of questions if I'm not quite sure about something.
KittyGirl 0 Newbie Poster
Is this what you mean?
while (max > 0.0 || max <= 10.0)
KittyGirl 0 Newbie Poster
I have to write a program for homework that asks for contestant scores, then outputs the total after the lowest and highest number are deleted. This is what I have so far. I can't use a sort since we haven't covered that yet and I'm not sure exactly how to subtract the lowest and highest number without sorting. Any help is much appreciated.
Thanks!
#include <iostream>
using namespace std;
int main()
{
int counter;
double sum;
double data [8];
cout<<"Enter data: ";
for (counter = 0; counter < 8; counter++)
data[counter] = 0.0;
for (counter = 0; counter < 8; counter++)
cin>>data[counter];
sum = 0;
for (counter = 0; counter < 8; counter++)
sum = sum + data[counter];
cout<<endl;
cout<<"Total points = "<<sum<<endl;
return 0;
}
KittyGirl 0 Newbie Poster
I have to write code that will prompt you to input a sentence, then it will output the number of vowels in the sentence. This is what I have so far. Can someone tell me what is wrong with it?
Thanks so much!
//Input a sentence, then return number of vowels in the sentence
#include <iostream>
using namespace std;
char ch(char vowel);
char isVowel (char a, char e, char i, char o, char u);
int main ()
char sentence;
char isVowel;
int number;
{
cout<<"Enter a sentence"<<endl;
cin>>sentence;
cout<<"There are "<<number<<" vowels in this sentence."<<endl;
return 0;
}
char isVowel (char a, char e, char i, char o, char u)
{
if (ch = 0)
return number;
else
return false;
}