Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Misunderstanding with how to use an integer w/ a very simple program

$
0
0
Hey hey,

this is my first time ever on the site posting, and as such, if you are reading this, I need you to understand that I am really, really new to C++. I've only even done Flash Actionscript, HTML and Javascript in the past but nothing in great detail as they stopped as my school curriculum stopped teaching it.
Hence I'm using this video series by DevHQLessons on youtube to help me out with learning the basics.
I just watched video on Class Members, and I think I get the concept, and in an attempt to put my knowledge to a bit of fun I tried to expand on what he did on the video (If you're interested).
Anywho this coding for a Win32 Console Application, and the idea of my program at this state is to ask the user what they would like to order from a takeaway restaurant, by answering y/n to the prompts and then, if needed, specifying the quantity of each product, then listing them down at the end. My first idea for specifying the quantity was to use an integer, however this posed me some problems.

The output at the end of the questions only ever lists how much chicken is ordered, nothing else. Additionally, the compiler freaks out if I don't initialize variables "chickens", or if I answer no to all the prompts. I hope I make sense, and if I don't, I'm incredibly sorry.

Here is the code, if relevant:
#include <iostream>

using namespace std;

class takeAway{
public:
void wantsChicken(){
	chicken = true;
}
void wantsNoodles(){
	noodles = true;
}
void wantsBurger(){
	burger = true;
}
bool chicken;
bool noodles;
bool burger;
};



int main(){
	char yn1;
	int qty1;
	char yn2;
	int qty2;
	char yn3;
	int qty3;
takeAway Customer1;
	cout << "You want chicken? Y/N" << endl;
	cin >> yn1;
	if(yn1 == 'y' || yn1 == 'Y') {
		Customer1.wantsChicken();
	cout << "How many chickens?" << endl;
	cin >> qty1;
	}

	cout << "You want noodles? Y/N" << endl;
	cin >> yn1;
	if(yn1 == 'y' || yn1 == 'Y') {
		Customer1.wantsChicken();
	cout << "How many noodles?" << endl;
	cin >> qty2;
	}

	cout << "You want burgers? Y/N" << endl;
	cin >> yn1;
	if(yn1 == 'y' || yn1 == 'Y') {
		Customer1.wantsChicken();
	cout << "How many burgers?" << endl;
	cin >> qty3;
	}
	cout << "You have ordered:" << endl;
	if(Customer1.chicken == true){
		cout << "- " << qty1 << "x Chicken(s)" << endl;
	}
	if(Customer1.noodles == true){
		cout << "- " << qty1 << "x Noodle(s)" << endl;
	}
	if(Customer1.burger == true){
		cout << "- " << qty1 << "x Burger(s)" << endl;
	}
	system("PAUSE");
	return 0;
}


Hopefully this is all covered, and if you could help, that would be much appreciated. I'm really hoping I can get some skills together with this language to the point of one day learning how to make a basic game.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>