If else statement

I only have one last problem before I complete my c++ project. I need to make a program which shows the review, to buy, availability of the product and will ask if the user still want to have another transaction, so far this all I've already done. My problem is that in the line63 whatever the user inputted in the program, it always execute what is in the cout statement. I tried all my best, I've re-read everything my notes regarding this but still I can't finish this. Any help/suggestion is greatly appreciated. Thanks!

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
#include <iostream>
#include <stdlib.h>
#include <string>
#include <conio.h>
using namespace std;

struct readymadepart2
{
       string gundam;
       string availability;
};

int main()
{ //start main
    int choice;
    char buychoice;
    char newtransac;
    
    readymadepart2 gunpla1;
    gunpla1.availability = "On-hand stock available";
    
    readymadepart2 gunpla2;
    gunpla2.availability = "On-hand stock available";
    
    readymadepart2 gunpla3;
    gunpla3.availability = "Currently out-of-stock";
    
    readymadepart2 gunpla4;
    gunpla4.availability = "On-hand/Online stock available";
    
    readymadepart2 gunpla5;
    gunpla5.availability = "Online stock available";
    
do{
    cout << "========== Gundam Models ==========" <<endl;
    cout << "1. Plastic Gunpla" <<endl;
    cout << "2. High Grade " <<endl;
    cout << "3. Real Grade" <<endl;
	cout << "4. Master Grade" << endl;
	cout << "5. Perfect Grade" << endl;
    cout << "Please enter your preferred choice: ";
    cin >> choice;
   	while (choice < 1 || choice > 5)//Check the user's input if acceptable or not.
	{
		cout<<"Please enter a valid Choice.";
		cout<<"Enter Choice : ";
		cin>>choice;
	}//END WHILE LOOP # 1
	system("CLS");
	if(choice==1)
	{
                 cout<<"===================================" <<endl;
                 cout<<"----------Plastic Gunpla-----------" <<endl;
                 cout<<"===================================" <<endl;
                 cout<<"Review: Manufactured in Japan or China by Bandai, which has an exclusive "
                     <<"license in manufacturing and marketing them around the world. "
                     <<"The models are typical of Plastic models, sprues of injection-molded Polystyrene (PS) parts which must be cut out before assembly. "
                     <<"Plastic Gunpla models kits are typically supplied with stickers and sometimes waterslide decals to apply extra colors "
                     <<"and markings as  seen in popular media such as TV shows, movies, manga or video games." <<endl<<endl;
                 cout<<"Availability: "<<gunpla1.availability<<endl<<endl;
                 cout<<"Would you like to buy this Gundam Model? [Y/N]: ";
                 cin>>buychoice;
                 if (buychoice=='Y'||'y')
                 {
                         cout<<"Thank you very much! Please do come again!"<<endl<<endl;
                         cout<<"Would you like another transaction? [Y/N]: ";
                         cin>>newtransac;
                         system("CLS");
                 }
                 else if(buychoice=='N'||'n')
   {
                 cout<<"ok";
                 }
     }
     else if(choice==2)
     {
                 cout<<"===================================" <<endl;
                 cout<<"-------------High Grade------------" <<endl;
                 cout<<"===================================" <<endl;
                 cout<<"Review: These kits at either 1:144 or 1:100 scale. These limited-run kits featured full snap-fit assembly, "
                     <<"an Internal Frame (which provides better range of motion and were more poseable), and utilized the molding technique known as System Injection "
                     <<"wherein multiple colors would be cast on the same part."<<endl;
                 cout<<"Availability: "<<gunpla2.availability<<endl;
                 cout<<"Would you like to buy this Gundam Model? [Y/N]: ";
                 cin>>buychoice;
                  if (buychoice=='Y'||'y')
                 {
                         cout<<"Thank you! Please come again!"<<endl;
                 }
     }
     else if(choice==3)
     {
                 cout<<"===================================" <<endl;
                 cout<<"-------------Real Grade------------" <<endl;
                 cout<<"===================================" <<endl;
                 cout<<"Review: These kits feature extensive detail and articulation, as well as a poseable skeletal frame comparable to the 1:100 Master Grade kits. "
                     <<"The RG line combines the best aspects of the other three Gunpla lines: The small size and affordable prices of the High Grade, the advanced inner frame "
                     <<"technology of the Master Grade and the massive part count of the Perfect Grade. The RG line is known for the Advanced MS Joint where the inner frame of "
                     <<"the suit is placed on a single gate for easy construction. The tagline for the Real Grade line is Excitement Embodied." <<endl;
                 cout<<"Availability: "<<gunpla3.availability<<endl;
                  if (buychoice=='Y'||'y')
                 {
                         cout<<"Thank you! Please come again!"<<endl;
                 }
     }
     else if(choice==4)
     {
                 cout<<"===================================" <<endl;
                 cout<<"-------------Master Grade----------" <<endl;
                 cout<<"===================================" <<endl;
                 cout<<"Review: Thse kits were first introduced in the summer of 1995, designed and made to higher standards than most other models. These kits take "
                     <<"much longer to construct and are often much more expensive than their lower-grade counterparts. More recent Master Grade plastic models typically feature a movable inner "
                     <<"frame system which enables extensive movement and bending of joints. "<<endl;
                 cout<<"Availability: "<<gunpla4.availability<<endl;
                 cout<<"Would you like to buy this Gundam Model? [Y/N]: ";
                 cin>>buychoice;
                  if (buychoice=='Y'||'y')
                 {
                         cout<<"Thank you! Please come again!"<<endl;
                 }
     }
     else if(choice==5)
     {
                 cout<<"===================================" <<endl;
                 cout<<"-------------Perfect Grade---------" <<endl;
                 cout<<"===================================" <<endl;
                 cout<<"Review: These kits come in standard 1:60 scale but are superbly detailed in terms of color and its inner frame, as well as normally possessing more "
                     <<"points of articulation, such as hands that articulate at the knuckles. The PG line has significant external and internal details, and recent ones have "
                     <<"featured light up gimmicks with LEDs. The PGs are some of the most expensive Gunpla produced and have sometimes been used to develop Master Grade technology."<<endl;
                 cout<<"Availability: "<<gunpla4.availability<<endl;
                 cout<<"Would you like to buy this Gundam Model? [Y/N]: ";
                 cin>>buychoice;
                  if (buychoice=='Y'||'y')
                 {
                         cout<<"Thank you! Please come again!"<<endl;
                 }
     }
}
   while (buychoice=='N'||'n');
   cout<<"Would you like another transaction? [Y/N]: ";
   cin>>newtransac;
   system("PAUSE");
}//end main

Change for
1
2
3
4
if( (buychoice == 'Y') || (buychoice == 'y'))
{
//code...
}


Also, if you do not need to print user input, it's useful to use some function that will change character to uppercase or lowercase, so you don't have to check for 2 options :)

Cheers!
Thanks! :) Btw last one question. How can I make my program exit when for example the user input "Y" then the program will execute this code.
1
2
3
4
5
6
7
 if (buychoice=='Y'||buychoice=='y')
                 {
                         cout<<endl;
                         cout<<"Thank you very much! Please do come again!"<<endl<<endl;
                         cout<<"Would you like another transaction? [Y/N]: ";
                         cin>>newtransac;
                 }


How can I make the program exited if the user answer "N" in last cout statement? Thanks Sir!
Last edited on
Nvm. Already done it. Thanks for the help! :)
Topic archived. No new replies allowed.