Online Toyota Cars Shopping

Hi everyone, I'm having big trouble with this code it seems like there are unnecessary variables I've used, and the whole point of shortening the code it's my problem because I can't do it without breaking the program. Thank you in advance guys I'll be very grateful if you can help me.

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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*     CSS PETA
       GROUP 3
       ICT-2      */
#include <iostream>
#include <string>
#include <ctime>
    void display_menu(const std::string &manufacturer,
                  const std::string names[],
	                  const int prices[],
	                  const size_t numCars ) {
	  std::cout << manufacturer << " Cars\n";
	  for ( size_t i = 0 ; i < numCars ; i++ ) {
	    std::cout << i + 1
	              << ". "
	              << names[i]
	              << " for "
	              << prices[i]
	              << " pesos\n";
	  }
	}
	int main()
	{
	  char YesNo, Yes_or_No;

	  do{
	  std::cout << "Welcome to Toyota Car Dealership\n" 
	       << "Here's the list of Cars: \n " ;
	  std::string toyota_car_names[] = {
	    "Camry",
	    "Corolla Altis",
	    "Vios",
	    "Wigo",
	    "Yaris",
	    "Corolla Cross",
	    "FJ Cruiser",
	    "Fortuner",
	    "Land Cruiser",
	    "Accord",
	    "Accord Hybrid",
	    "Civic",
	    "Clarity",
	    "CR-V",
	    "HR-V",
	    "Insight",
	    "Odyssey"
	  };
	  int toyota_car_prices[] = {
	    2042000,
	    1595000,
	    1056000,
	    700000,
	    1065000,
	    1650000,
	    2083000,
	    2414000,
	    4950000,
	    2308000,
	    2508000,
	    1115000,
	    1249000,
	    1678000,
	    1296000,
	    1038000,
	    2298000
	  };
	  
	  display_menu("Toyota",toyota_car_names,toyota_car_prices,17);
	  std::cout << "Input Number According to the type of Car: ";
	  int Cars;
	  std::cin >> Cars;
	  std::cout << "You selected "
	            << toyota_car_names[Cars-1]  
	            << " for "
	            << toyota_car_prices[Cars-1]
	            << " pesos\n";
	
	  std::cout << "To be Comformed Type Y Yes, if type N if No: ";
	  std::cin >> Yes_or_No;
	  if (Yes_or_No == 'y' || Yes_or_No == 'Y') {
	    std::cout << "You Ordered "
	              << toyota_car_names[Cars-1]
	              << std::endl;
	         std::cout << "What Color of " 
	            << toyota_car_names[Cars-1] 
				<< " do you want?\n";
	  int Color;
	  std::cout << "1. Black\n"
	            << "2. Blue\n"
	            << "3. Gray\n"
	            << "4. Green\n"
	            << "5. Red\n"
	            << "6. Cyan\n"
	            << "7. Yellow\n";
      std::cout << "Please select the Number of Color: ";
      std::cin >> Color;
      if ((Color < 1 ) && (Color > 7)) {
      	std::cout << "You pick the Wrong number.\n";
	  }
      else if ((Color >= 1) && (Color <= 7)) {
	   switch(Color) {  
	        case 1:
			   std::cout << "You pick color Black\n";
			   break;
	   		case 2:
			   std::cout << "You pick color Blue\n";
               break;
	   		case 3:
			   std::cout << "You pick color Gray\n";
			   break;
		    case 4:
			   std::cout << "You pick color Green\n";
			   break;
		    case 5:
			   std::cout << "You pick color Red\n";
			   break;
		    case 6:
			   std::cout << "You pick color Cyan\n";
			   break;
	  	    case 7:
			   std::cout << "You pick color Yellow\n";
			   break;
}

	  std::cout << "Do you want to order more? type Y if yes and type N if no: ";
	  std::cin >> YesNo;
	    if (YesNo == 'n' || YesNo == 'N') {
	    	int Total, Payment, Change;
	    	Total = toyota_car_prices[Cars-1];
	    	std::cout << "Total Amount: " << Total << "\n";
			std::cout << "Enter The Amount of Payment\n";
	    	std::cin >> Payment;
			Change = Payment - Total;
	    	if(Change >= 1) {
	    		std::cout << "Change: " << Change << "\n ";
	    	}
	        else if(Change == 0) {
	        	std::cout << "You paid the exact amount of money needed.\n";
			}
			else if(Change <= -1) {
	    		std::cout << "You don't have enough money.\n";
			}
			else {
				std::cout << "It seems like there's an error on the system.\n";
			}
		}
			  std::cout << "************************************************\n"
	            << "              Thank for your purchase           \n"
	            << "          We love to hear your feedback         \n" 
	            << "              Call: (02) 8-361-8794             \n" 
	            << "               Globe: 09272533969               \n"
	            << "            Email: JKRBN99@gmail.com            \n"
	            << "              Website: Toyota.com.ph            \n"
	            << " ************************************************\n";
		}
          else 	if (Yes_or_No == 'n' || Yes_or_No == 'N') {
	    std::cout << "You Canceled the order.\n";
	  }
	}
}
	  	while(YesNo == 'y' || YesNo == 'Y');
}

Also, I can't do the thing where you will calculate all of the current orders to give the receipt. Advance thank you guys for those who wanna help. I'm just learning c++ for 4 weeks now. I'm just a newbie.
Last edited on
You can put the colours into another array (like car_names and car_prices).
Not really a tip for shortening your code, but I will say you should make sure you have consistent indentation. It is hard to read your code because you are using a mix of spaces and tabs, and you sometimes tab when it isn't necessary, and sometimes overtab.

You also have two different variables,
char YesNo, Yes_or_No;
From the names of these variables alone, it is not clear what their purposes are.
It would be better if you named one of the variables "order_confirmation" and the other "order_more"/"order_again" or something like that.
Also, your Yes_or_No variable is only used within the inner confirmation part of your code, so it can be declared in a more narrow scope.

Also, I can't do the thing where you will calculate all of the current orders to give the receipt
You need to save the current orders in some way. One option would be to write to a receipt file each time the user places an order, and then print that receipt at the end of the program. Another option would be to use another vector or array to store each {car type, color} pair. You could use a struct for this,
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
#include <vector>

struct CarOrder {
    int car_index;
    std::string color; // or color_index, if you go with what seeplus said
};

//
int main()
{
    vector<CarOrder> orders;

    // ... user makes order
    {
        CarOrder order { Cars - 1, Color - 1 };
        orders.push_back(order);
    }

    // ...
    // print receipt:
    for (const CarOrder& order : orders)
    {
        // print order
    }
}


PS: The title of your post totally sounds like spam :D no worries though it obviously isn't.
Last edited on
Topic archived. No new replies allowed.