mercredi 4 mai 2016

C++ Numeric values are not printing correctly

                                 Main Program
#include<iostream>
#include <iomanip>
#include"pizza.h"
using namespace std;

int main()
{

menuItem item;
menu:
item.getMenu();//Menu Prompt

cout << "\nI would like number: " << flush;
int menuChoice;
cin >> menuChoice;
while (menuChoice < 1 || menuChoice > 3)
{
    cout << "\nINVAILD INPUT:\nEnter a Value that corresponds with your menu choice" << endl;
}
if (menuChoice == 1)
{
    item.getPizza();
}
if (menuChoice == 2)
{
    item.getSandwhich();
}
if (menuChoice == 3)
{
    item.getSide();
}




int ready4checkout;
cout << "\n\n~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~" << endl;
cout << "\nAre you ready to checkout?\n" << endl;
cout << "checkout = 1\nAdd to the order = 2" << endl;
cout << "\nI would like to:" << flush;
cin >> ready4checkout;
if (ready4checkout == 1)
{
    item.addcheckout();
}
if (ready4checkout == 2)
{
    goto menu;
}
    cin.ignore();
    cin.get();
}


                          Header File




#include<iostream>
#include <iomanip>
using namespace std;

class menuItem
{
protected:
float smallPizza = 5.99;
float mediumPizza = 6.99;
float largePizza = 9.99;
float halfSandwhich = 6.00;
float wholeSandwhich = 8.00;
float bonelessWings = .70;
float breadStix = 4.99;

public:
float checkout;
float pizzaCheck;
float sandCheck;
float sideCheck;

menuItem item(float smallPizza, float mediumPizza, float largePizza, float halfSandwhich, float wholeSandwhich, float bonelessWings, float breadStix,float checkout);


string getMenu()
{
    string menu;
    cout << "~*~*~*~*~*~*~*~ Welcome to Pizza Italiano! ~*~*~*~*~*~*~*~*~\n\n" << endl;
    cout << "~~~~~~~~~~~~~~~~~ Main Menu ~~~~~~~~~~~~~~~~~~" << endl;
    cout << "Enter the value of the food that you wish to devour:\n" << endl;
    cout << "\n1.Pizza\n2.Sandwhich\n3.Appetizer" << endl;
    return menu;
}

string getPizza()
{
    float pizzaCheck;
    string pizza;
    float pizzaSize;
    pizza:
    cout << " \n~~~~~~ How would you like your pizza made? ~~~~~~\n" << endl;
    cout << "   Size" << endl;
    cout << "-----------" << endl;
    cout << "1. Large                 $9.99 \n2. Medium                $6.99 \n3. Small                 $5.99" << endl;
    cout << "\nI would like the number: " << flush;
    cin >> pizzaSize;
    cin.ignore();
    while (pizzaSize < 1 || pizzaSize > 3)
    {
        cout << "\nINVAILD INPUT:\nEnter a Value that corresponds with your menu choice" << endl;
        goto pizza;
    }
    if(pizzaSize == 1)
    {
        cout << "\n****You have selected a Large pizza****" << endl;
        pizzaCheck = pizzaSize;
        pizzaCheck = largePizza + pizzaCheck;
    }
    else if(pizzaSize == 2)
    {
        cout << "\n****You have selected a Medium Pizza****" << endl;
        pizzaCheck = pizzaSize;
        pizzaCheck = mediumPizza + pizzaCheck;
    }
    else
    {
        cout << "\n****You have selected a Personal pizza****" << endl;
        pizzaCheck = pizzaSize;
        pizzaCheck = smallPizza + pizzaCheck;
    }
    cin.get();
    return pizza;
}
string getSandwhich()
{
    string sandwhich;
    float sandSize;
    Sandwhich:
    cout << "~~~~~~~~~~~~ What size would you like your sandwhich to be? ~~~~~~~~~~~~~~~\n\n" << endl;
    cout << "1. Six inch             $6.00\n2. Twelve inch           $8.00" << endl;
    cout << "I would like number:" << flush;
    cin >> sandSize;
    while (sandSize < 1 || sandSize > 2)
    {
        cout << "\nINVAILD INPUT:\nEnter a Value that corresponds with your menu choice" << endl;
        goto Sandwhich;
    }
    if (sandSize == 1)
    {
        cout << "**** You have selected a six inch sub ****" << endl;

        sandCheck = halfSandwhich + sandSize;

    }
    else 
    {
        cout << "**** You have selected a 12 inch sub ****" << endl;

        sandCheck = wholeSandwhich + sandSize;
    }
    return sandwhich;
}
string getSide()
{
    string Appetizer;
    float side;
    sides:
    cout << "~~~~~~~~~~~~~~~ Which appetizer would you like? ~~~~~~~~~~~~~~~~~\n\n" << endl;
    cout << "1. Boneless Wings            .70\n2. BreadStix               $4.99\n\n" << endl;
    cout << "I would like the number:" << flush;
    cin >> side;
    while (side < 1 || side > 2)
    {
        cout << "\nINVAILD INPUT:\nEnter a Value that corresponds with your menu choice" << endl;
        goto sides;
    }
    if (side == 1)
    {
        cout << "\n**** You have selected Boneless wings ****\n" << endl;
        cout << "How many wings would you like?\n" << endl;
        cout << "I would like this many wings:" << flush;
        int wings;
        cin >> wings;
        cout << "\n**** You will recieve " << wings << " wings. ****" << endl;
        side = sideCheck;
        sideCheck = bonelessWings += sideCheck;
    }
    else
    {
        cout << "\n**** You have selected an order of breadstix ****" << endl;
        side = sideCheck;
        sideCheck = breadStix += sideCheck;
    }
    return Appetizer;
}
float addcheckout()
{
    checkout = pizzaCheck;
    cout << "\nYour total is " << checkout << endl;
    cout << "\nThank You for your purchase!";
    return checkout;
}




};

At the end of the program, when it gives the checkout total, it gives a value something like -1.07374e.+008

I am still learning how to code, and I am stumped on this one. Any help would be much appreciated!

Aucun commentaire:

Enregistrer un commentaire