Basic Store

closed account (zUjEwA7f)
Hello! I'm a beginner, and i'm starting to get the grasp of a lot of aspects. I'm trying to make a basic store. You have $20. This $20 is changeable, meaning you can add to it (by selling or buying). Red apples cost $2 and Green apples cost $3 (Shut up, green apples are better no matter what you say)

I want a menu that will allow a semi-"userface"
Im not wanting to code any GUI as of no, this is just pure c++ console

I want the basic layout to be;

Welcome! Please purchase some items
Red Apples cost $2
Green Apples cost $3

You have $20 <---- Update based on later input

Inventory
----------
[NUMBER YOU HAVE] xRed Apples
[NUMBER YOU HAVE] xGreen Apples
----------

Buy X Red Apples <---- Be able to switch between with "W" or "S"
Buy X Green Apples




Anyways, this is as far as i can get. Im not sure how to make the rest. Thanks!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  #include <iostream>
using namespace std;

int Wallet = 20;
int RedApp_P = 2;
int GreApp_P = 3;
int UsrInputR;
int UsrInputG;

int main (){
	
	cout << "Welcome! Please purchase some items" << endl;
	
	cout << "Red apples cost $2" << endl << "Green apples cost $3" << endl << endl;
	
	cout << "You have: $" << Wallet << endl;
	cout << "Inventory" << endl;
	cout << "---------------" << endl;
	cout << "Buy " << UsrInputR << " Red Apples" << endl;
	cout << "Buy " << UsrInputG << " Green Apples" << endl << endl << endl << endl;
	
	return 0;
}
in
Last edited on
first off if you want user input you need to use cin>>userINputR;
and you shouldn't initialize wallet to $20 unless everyone in your store starts off with $20 credit.

switch statements are very good for menus. http://www.tutorialspoint.com/cplusplus/cpp_switch_statement.htm

you should also put those variables inside your main function make things a little simpler to read.
You're springing too fast. Learn if statements at least.
For starting out, don't use global variables unless your program is needing it, but for this program it is best to declare and initialize those variables inside main. You want to work inside your main function for awhile learning the basic "IF statement, Switch, For loops, while loops and DO while loop" Keep things simple and basic because trying to work outside main and not knowing how to take a user input or an IF statement is asking for trouble there. Because global variables should be used for different things or things when you need to use the heap. But all of which is beyond what you need to know at this time. If you're reading a book or using this sites tut. Read the book/tuts but most importantly do whats in the book! Not just read it.

Get those basic things down and you will learn how to make your own functions and how to pass variables through them. But start small because it's too much to try to take in all at once. One of the things I recommend is using "Youtube" many of them have good series on C++ as well as you will be shown different type of styles of programming and bad styles. As you progress you will be identify which user is worth following and learning from. There is a ton of things about C++ just remember there is always learning to do even if you have been doing it 20+ years or not. Take it small!
Topic archived. No new replies allowed.