D
David
What can I do to accept either uppercase or lower case " y or n" in the
program below.?
any help will be appreciated
#include <iostream>
using namespace std;
//class definigtion
class Pizza
{
public:
Pizza (const char top [] = "cheese", const int size = 12, const double
Price = 8.99);
void setValue();
void displayValues();
private:
char topping [20];
int diameter;
double price;
};
//constructor
Pizza:izza (const char top[], const int size, const double Price)
{
strcpy (topping, top);
diameter = size;
price = Price;
}
//set pizza function
void Pizza::setValue()
{
cout << "Please enter your choice of topping: "<<'\n';
cout<<'\n';
cin>>topping;
cout<< '\n';
cout<< "Please enter your choice of size: "<<'\n';
cout<< '\n';
cin>>diameter;
cout<<'\n';
if (topping != "cheese")
price = 9.99;
if (diameter > 12)
price = price + 1.5;
}
//call pizza function
void Pizza::displayValues ()
{
cout<<"Your choice of pizza is a " <<topping<< " " <<diameter<< "in. pizza
for " "$" <<price<<'\n';
}
//start the main engine
void main()
{
char option[2];
Pizza p;
cout<< '\n';
cout<< '\n';
cout<< " MAHARAJA'S PIZZA" <<'\n\n';
cout<< "Do you want a cheese 12 in. pizza? y/n: ";
cin>> option;
if (option[0] == 'n')
p.setValue();
p.displayValues();
}
program below.?
any help will be appreciated
#include <iostream>
using namespace std;
//class definigtion
class Pizza
{
public:
Pizza (const char top [] = "cheese", const int size = 12, const double
Price = 8.99);
void setValue();
void displayValues();
private:
char topping [20];
int diameter;
double price;
};
//constructor
Pizza:izza (const char top[], const int size, const double Price)
{
strcpy (topping, top);
diameter = size;
price = Price;
}
//set pizza function
void Pizza::setValue()
{
cout << "Please enter your choice of topping: "<<'\n';
cout<<'\n';
cin>>topping;
cout<< '\n';
cout<< "Please enter your choice of size: "<<'\n';
cout<< '\n';
cin>>diameter;
cout<<'\n';
if (topping != "cheese")
price = 9.99;
if (diameter > 12)
price = price + 1.5;
}
//call pizza function
void Pizza::displayValues ()
{
cout<<"Your choice of pizza is a " <<topping<< " " <<diameter<< "in. pizza
for " "$" <<price<<'\n';
}
//start the main engine
void main()
{
char option[2];
Pizza p;
cout<< '\n';
cout<< '\n';
cout<< " MAHARAJA'S PIZZA" <<'\n\n';
cout<< "Do you want a cheese 12 in. pizza? y/n: ";
cin>> option;
if (option[0] == 'n')
p.setValue();
p.displayValues();
}