Need help with my C++ menu program

The only problem I have with my code is the result(no errors or warnings). It always gives me $2005371809 as my answer. for example, for each of my prices I input 300, 50, and 10 dollars as my sample data. The answer should have been $360 instead of that huge number as indicated by my formula. Also, please offer some suggestions to improve my program if you can.

Edit- Do you think this junk value that keeping getting has to do with the data types that I'm using?

Edit 2- well I've made huge progress by creating 3 new variables(int price 1, 2 and 3.) and by putting the formula inside the last else if statement(I'm not sure if that did anything really). The problem now is that I am force to input 3 integers otherwise the answer is off by 1 or 2. for example, if you only pick option 2 and input 300 and decide to press option 5, then the answer will be 302. Another example is if you input 300 then 50, you get 351. Most likely it has something with not inputting a value in one of the variables(like inputting 300 in price1, but leaving price2 and 3 empty.). So my new question is how do I force the program to leave price2 or 3 as 0 in case a customer only wants to inputs a value in price1. Do I have to create multiple formulas to do that?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <iostream> // Library used for basic input and output functions.
#include <string>   // A library for string functions.
#include <cstdlib>  // Has the function system pause.
#include <iomanip>  // Required for setw.

using namespace std;

int main()
{
   string userName; // The name of the user using the menu.
   int option; /* A variable that will be used for each if-if/else
                  statement. */
   int price1 = 300 || 600 || 10 || 50;  // variables for calculations.
   int price2 = 50 || 30 || 7 || 13;
   int price3 = 10 || 6 || 5 || 15;


  cout << "Please enter your name: "; /* Asking the user to input
                                          their name. */
       getline(cin,userName);

  cout << "\nHello " << userName << " and welcome to Luis' animal";
  cout << " store.\n"; /* A little welcome message. */
  cout << "\nPress enter to continue.\n";

       system("pause>nul");

    do /* This loop is meant to continuously repeat the user's input
           until they decide to exit the program. */
{
// A menu for the user.
cout << "\n----------------------Menu---------------------------------";
cout << "\n1).View a list of animals currently available." << endl;
cout << "2).The different prices for each animal." << endl;
cout << "3).The name of the brand and price of the food." << endl;
cout << "4).A list of accessories for each animal." << endl;
cout << "5).Exit the program. " << endl;
cout << "-----------------------------------------------------------\n";
// Asking the user to input their choice.
cout <<"\n" << userName << ", please input a number corresponding to";
cout << " the choice that you want. ";
cin >> option; /* This will force the user to input an  answer and
                  save that anser to the variable option. */

    if(option == 1) // If the user chooses option 1.
{
        // A list of animals currently available.
cout << "\n-----------------List of Animals---------------------------";
cout << "\n1).Dog:" << setw(11) << " Beagle" << endl;
cout << "2).Cat:" << setw(11) << " Birman" << endl;
cout << "3).Fish:" << setw(12) << " Goldfish" << endl;
cout << "4).Reptile:" << setw(11) << " Corn Snake" << endl;
cout << "-----------------------------------------------------------\n";

cout << "\nPress enter to continue and return back to the menu.\n";

        system("pause>nul");
}
    else if(option == 2) // If the user chooses option 2.
{
        // The names and prices for animals currently available.
cout << "\n----------------Price Per Animal---------------------------";
cout << "\n   Names       Prices" << endl;
cout << "\n1).Beagle: " << setw(9) << " $300" << endl;
cout << "2).Birman: " << setw(9) << " $600" << endl;
cout << "3).Goldfish: " << setw(7) << " $10" << endl;
cout << "4).Corn Snake: " << setw(5) << " $50" << endl;
cout << "-----------------------------------------------------------\n";
cin >> price1;

cout << "\nPress enter to continue and return back to the menu.\n";

        system("pause>nul");
}
    else if(option == 3) // If the user chooses option 3.
{
        // The brand for each animal as well as the price.
cout << "\n--------The Price and Name of the Food---------------------";
cout << "\n      Brand Name               Price" << endl;
cout << "\n1).BlackWood-(Beagle): "<< setw(12) << " $50" << endl;
cout << "2).Purina-(Birman): " << setw(15) << " $30" <<  endl;
cout << "3).Aqueon Pellets-(Goldfish): " << setw(5) << " $7" << endl;
cout << "4).Artic Mice-(Corn Snake): " << setw(7) << " $13" << endl;
cout << "-----------------------------------------------------------\n";
cin >> price2;

cout << "\nPress enter to continue and return back to the menu.\n";

        system("pause>nul");
}
    else if(option == 4) // if the user chooses option 4.
{
        // Accessories for your animals.
cout << "\n------------------Animal Accessories-----------------------";
cout << "\n      Toy Name                        Price" << endl;
cout << "\n1).Beagle(Chew Toy)" << setw(23) << "   $10" << endl;
cout << "2).Birman(Fly Teaser)" << setw(22) << "   $6 " << endl;
cout << "3).Goldfish(Gravel)" << setw(24) << "     $5 " << endl;
cout << "4).Corn Snake(Branches)" << setw(20) << "  $15" << endl;
cout << "-----------------------------------------------------------\n";
cin >> price3;

cout << "\nPress enter to continue and return back to the menu.\n";

       system("pause>nul");
}
    else if(option == 5) // If the user chooses option 5.
    {
    int totalPrice = price1 + price2 + price3; /* The total sum of each
                                               individual variable. */
        cout << "\n\nYour total is $" << totalPrice << endl;
        cout << "\nGoodbye, and have a nice day. " << endl;
    }
    else // If the user inputs an invalid choice.
    {
        // Error message.
        cerr << "\nError, invalid entry. Please try again." << endl;

        system("pause>nul");
    }
 }
    while(option != 5); // A conditional statement.

    return 0;

}
Last edited on
Well I was finally able to solve my dilemma(took about 3 hours jeesh). All I had to do was set all of my 3 price variables to 0 so that It wouldn't give my any junk values.
Last edited on
Topic archived. No new replies allowed.