1 Replies - 1311 Views - Last Post: 18 March 2013 - 05:43 AM Rate Topic: -----

#1 ImmaNew  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-February 13

[Question] Options Program

Posted 18 March 2013 - 04:19 AM

So, I want to make a program like, there's a choices/options.
Example this one.


CAFETERIA

[A] - Snacks
[B] - Drinks
Enter your choice:

//If they enter "A" another option will appear//

Like this:
Snacks

[A] - Snack1..............$1
[B] - Snack2..............$1
[C] - Snack3..............$1
Enter your choice:

//And then, if they choose any of these options, the name and price of the selected option should appear.//

Like this: Name of choice: Snack1
Price: $1

And then, they will be ask if they want to order some drinks.

Like this: Do you want somee drinks? [Y] or [N]
if they enter "Y" it will proceed to the Drinks option and if "N" the program will terminate.

Like this:
Drinks

[A] - Drinks1
[B] - Drinks2
[C] - Drinks3

//And vice versa, I mean if they choose "B" on the first option.. the Drinks choices should appear first.//



And I'm currently working on it.. but I can't get it..

#include<stdio.h>
#include<conio.h>
#define p printf
#define s scanf

void main()
{
clrscr();
int choice,choice2;
int a,A,b,B,c,C,y,Y,n,N;
	p("\t\t\tCAFETERIA\n\n");
	p("[A] - Snacks\n");
	p("[B] - Drinks\n\n");
	p("Enter your choice: ");
	s("%s",&choice);
	if(choice=='a'||choice=='A'){
	p("\nSNACKS\n\n");
	p("[A] - Piatos................12.00\n");
	p("[B] - Nova..................15.00\n");
	p("[C] - Lays..................101.00\n");
	}
	else if(choice=='b'||choice=='B'){
	p("\nDRINKS\n\n");
	p("[A] - Coke..................10.00\n");
	p("[B] - Sprite................15.00\n");
	p("[C] - Sparkle...............12.00\n");
	}
	else {
	p("Error!");
	}

	if (choice=='a'||choice=='A'){
	p("Enter letter of choice: ");
	s("%d",&choice);

	if (choice=='a'||choice=='A'){
	p("\nName of choice: Piatos\nPrice: 12.00\n");
	}
	}






	getch();
	}


Ooops, I forgot to tell, it should be in Turbo C..
I'm just a beginner in programming :/

Is This A Good Question/Topic? 0
  • +

Replies To: [Question] Options Program

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3453
  • View blog
  • Posts: 10,659
  • Joined: 05-May 12

Re: [Question] Options Program

Posted 18 March 2013 - 05:43 AM

You are incorrectly gathering your input:

Quote

09 int choice,choice2;
:
15 s("%s",&choice);

You declared choice to be an integer, yet you are telling scanf() to input a string.

Anyway a couple bits of advice:
1) Drop Turbo C and move on to a more modern compiler.
2) Avoid using macros to replace functions. Saving yourself some characters of typing by using 'p' and 's' instead of printf and scanf will cause you serious problems later when you declare a variable named 's'.
3) Avoid using two variables that only are different by upper case vs. lower case. When you have hundreds of lines of code, or it's 3AM in the morning, this will bite you as you search for the elusive bug.

This post has been edited by Skydiver: 18 March 2013 - 05:43 AM

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1