string subChoice ="";
getline(cin,subChoice);

Can anybody help me???
What these lines do? and how are to be used?

The first line just declares a variable of type std::string

The second line causes all keyboard input up to the '\n' (carriage return) to be sent to the string object. So if you typed "Hello World" <Return key> then the string subChoice would contain "Hello World".

Copy and paste this into your compiler's editor, compile it, and run it to see for yourself what it does

#include <iostream>
#include <string>

int main()
{
   std::string subChoice;
   std::cout << "Enter some text\n";
   std::getline(std::cin, subChoice);
   std::cout << "You entered \"" << subChoice << "\"\n";
}

Sorry but im a bit new with these C++ thing and i only know #include<iostream.h>
what's #include<string> do???

im really sorry for the inconvinience sir i just want to learn^-^

You obviously need to read some c++ tutorials. iostream.h is long obsolete and should no longer be used. Current c++ header files do not have .h extension <string> and <iostream>

<string> is the header file that declares the c++ std::string class
<iostream> declares std::cin, std::cout, etc.

There are quite a few header files, and you will learn them by reading books and/or online tutorials. Here are a few ebooks you can download for free.

thank you very much for your kindness sir i'll study these hard^-^

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()
{
	int choice;
	int beefQuant=0;
	int pkbfQuant=0;
	int veggQuant=0;
	int gdpgQuant=0;
	int drnkQuant=0;
	double subTotal;
	double tax;
	double totalDue;
	double beefTotal=0;
	double pgbfTotal=0;
	double veggTotal=0;
	double gdpgTotal=0;
	double drnkTotal=0;
	
	cout<<"Welcome to Abisado’s Delights"<<endl;
	cout<<"Please choose what you wanna eat from the selection by entering the item number on the left"<<endl;
	cout<<endl;
	cout<<"..................................MENU........................................"<<endl;
	cout<<"Item# Description--------------------------------------------------------Price"<<endl;
	cout<<"______________________________________________________________________________"<<endl;
	cout<<"[1] Beefy Experience:  Beef Teriyaki w/ Rice...............................120.75"<<endl;
	cout<<endl;
	cout<<"[2] Pork and Beef Supreme: Beef Strips w/ Rice and Pork Buns..............90.25"<<endl;
	cout<<endl;
	cout<<"[3] Veggie Surprise:  Fresh Salad with Onion Sauerkraut......................100.00"<<endl;
	cout<<endl;
	cout<<"[4] All Time Family Favorite: Grilled Pig w/ Rice and Chili Sauce for 12 Servings .....395.00"<<endl;
	cout<<endl;
	cout<<"[5] DRINKS: one-size and free refills......................................85"<<endl;
	cout<<endl;

	while(choice=1||2||3||4||5){
	cin>>choice;
	}
	switch (choice)
	{
	case 1:
		beefQuant=beefQuant+1;
		beefTotal=beefQuant*120.75;
		break;
	case 2:
		pkbfQuant=pkbfQuant+1;
		pkbfTotal=pkbfQuant*90.25;
		break;
	case 3:
		veggQuant=veggQuant+1;
		veggTotal=veggQuant*100.00;
		break;
	case 4:
		gdpgQuant=gdpgQuant+1;
		gdpgTotal=gdpgQuant*395.00;
		break;
	case 5:
		drnkQuant=drnkQuant+1;
		drnkTotal=drnkQuant*85.00;
		break;
	default:
		system("cls");
		cout<<endl;
		cout<<"You have ordered the following:"<<endl;
		cout<<"___________________"<<endl;
		if(beefQuant!=0){
			cout<<beefQuant<<"  #1      "<<beefTotal<<endl;
		}
		if(pkbfQuant!=0){
			cout<<pkbfQuant<<"  #2      "<<pkbfTotal<<endl;
		}
		if(veggQuant!=0){
			cout<<veggQuant<<"  #3      "<<veggTotal<<endl;
		}
		if(gdpgQuant!=0){
			cout<<gdpgQuant<<"  #4      "<<gdpgTotal<<endl;
		}
		if(drnkQuant!=0){
			cout<<drnkQuant<<"  #5      "<<drnkTotal<<endl;
		}
		cout<<fixed<<setprecision(2)<<endl;
		cout<<"___________________"<<endl;
		subTotal=(beefTotal+pgbfTotal+veggTotal+gdpgTotal+drnkTotal);
		tax=(subTotal*.12);
		totalDue=(subTotal+tax);
		cout<<"Subtotal:  "<<subTotal<<endl;
		cout<<"Tax:  "<<tax<<endl;
		cout<<"___________________"<<endl;
		cout<<"Total Due   "<<totalDue<<endl;
	}
	{
		
return 0;
}

Sir how's this??? can you help me again???? im a bit confused.
The food is a little weird but disregard that please hahah^-^

Sir there is an error here that says
C:\Users\cs10l-b7-23\Desktop\Project Draft.cpp(92) : fatal error C1004: unexpected end of file found
what does that mean

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()
{
	int choice;
	int beefQuant=0;
	int pkbfQuant=0;
	int veggQuant=0;
	int gdpgQuant=0;
	int drnkQuant=0;
	double subTotal;
	double tax;													//this is double because there are items in the menu that has a decimal value representing cents
	double totalDue;
	double beefTotal=0;
	double pkbfTotal=0;
	double veggTotal=0;
	double gdpgTotal=0;
	double drnkTotal=0;
	
	cout<<"Welcome to Abisado’s Delights"<<endl;
	cout<<"Please choose from the available menu by using the item number on the left"<<endl;
	cout<<endl;
	cout<<"..................................MENU........................................"<<endl;			// this menu as i said in the project description must be updated regularly from the available menu to the price range of each
	cout<<"Item# Description--------------------------------------------------------Price"<<endl;			// the food is kinda odd but nevermind that its just an example
	cout<<"______________________________________________________________________________"<<endl;
	cout<<"[1]Beefy Experience:Beef Teriyaki w/ Rice...............................190.75"<<endl;
	cout<<endl;
	cout<<"[2]Pork and Beef Supreme:Beef Strips w/ Rice and Pork Buns..............160.25"<<endl;
	cout<<endl;
	cout<<"[3]Veggie Surprise:Fresh Salad with Onion Sauerkraut....................125.00"<<endl;
	cout<<endl;
	cout<<"[4]Family Meal:Grilled Pig w/ Rice and Chili Sauce for 12 Servings .....470.00"<<endl;
	cout<<endl;
	cout<<"[5]DRINKS:One-size and free refills......................................85.00"<<endl;
	cout<<endl;

	do{
	cin>>choice;
	}while( choice >= 1 && choice <= 5) ;
	switch (choice)
	{
	case 1:
		beefQuant=beefQuant+1;				//the acronyms i used is a bit odd you can use any acronym you want w/c ever suits you best
		beefTotal=beefQuant*120.75;
		break;
	case 2:
		pkbfQuant=pkbfQuant+1;
		pkbfTotal=pkbfQuant*90.25;
		break;
	case 3:
		veggQuant=veggQuant+1;
		veggTotal=veggQuant*100.00;
		break;
	case 4:
		gdpgQuant=gdpgQuant+1;
		gdpgTotal=gdpgQuant*395.00;
		break;
	case 5:
		drnkQuant=drnkQuant+1;
		drnkTotal=drnkQuant*85.00;
		break;
	default:
		system("cls");
		cout<<endl;
		cout<<"You have ordered the following:"<<endl;
		cout<<"___________________"<<choice<<endl;
		if(beefQuant!=0){
			cout<<beefQuant<<"  #1      "<<beefTotal<<endl;
		}
		if(pkbfQuant!=0){
			cout<<pkbfQuant<<"  #2      "<<pkbfTotal<<endl;
		}
		if(veggQuant!=0){
			cout<<veggQuant<<"  #3      "<<veggTotal<<endl;
		}
		if(gdpgQuant!=0){
			cout<<gdpgQuant<<"  #4      "<<gdpgTotal<<endl;
		}
		if(drnkQuant!=0){
			cout<<drnkQuant<<"  #5      "<<drnkTotal<<endl;
		}
		cout<<fixed<<setprecision(2)<<endl;
		cout<<"___________________"<<endl;
		subTotal=(beefTotal+pkbfTotal+veggTotal+gdpgTotal+drnkTotal);
		tax=(subTotal*.12);		                                           	// this program is set to the current tax rate implemented by the Philippine Government any changes must also be updated if any
		totalDue=(subTotal+tax);
		cout<<"Subtotal:  "<<subTotal<<endl;
		cout<<"Tax:  "<<tax<<endl;
		cout<<"___________________"<<endl;
		cout<<"Total Due   "<<totalDue<<endl;
	}
	
		
return 0;
}

It runs but it once you input something it does nothing
i just kept on choosing and nothing happens nid help masters

It's because all your response outputs are part of the default case of your switch. You only see them if you make an invalid selection. In addition, you only see them if you have ordered at least one (1) of the particular item reported. However, the structure of the program precludes this because you don't have it contained within a loop. If you place a valid order, the order is logged and the program ends. If you attempt to place an invalid order, the program catches it, but doesn't report the error (doesn't provide any feedback). Because there is no feedback, it looks "hung" even though it's not, it's just waiting for a new menu selection.

Run the program and enter a 6. The program will look "stuck" because the input loop is waiting for another input, but doesn't say so.

You need to do at least 2 things to make a program such as this function properly:
1. Either expand the scope of your do-while loop to include more than just your input statement or add another loop of some sort that includes all of your input and output statements.
2. Move Lines 68-93 out of the switch default so that they run at the appropriate time(s).

Keep an algorithm similar to this in mind:

//pseudocode
welcome user
begin ordering loop
  begin menuInput loop
    display menu
    get user input
    if valid input
      if new food ordered
        calculate new user total
        exit menuInput loop
      else if end order selected
        exit menuInput loop
    else
      inform user of error
  end menuInput loop
  display user total
  ask if would like to add to order
end ordering loop
display user final total
end program

You already have most of this covered. You just need to re-arrange the parts of your code to make the loops and switch work properly.

Edited 6 Years Ago by Fbody: n/a

You need to include the switch statement in your do while loop otherwise, you will never exit the do while loop.

Also, with your switch statement, everything in your default will never run.

//None of this code will ever run. If you enter a number to break your do while loop, none of your other cases will run. Your default doesn't have a break in it.
default:		
         system("cls");
	cout<<endl;
	cout<<"You have ordered the following:"<<endl;
	cout<<"___________________"<<choice<<endl;
	if(beefQuant!=0){
		cout<<beefQuant<<"  #1      "<<beefTotal<<endl;
		}
	if(pkbfQuant!=0){
		cout<<pkbfQuant<<"  #2      "<<pkbfTotal<<endl;
		}
	if(veggQuant!=0){
		cout<<veggQuant<<"  #3      "<<veggTotal<<endl;
		}
	if(gdpgQuant!=0){
		cout<<gdpgQuant<<"  #4      "<<gdpgTotal<<endl;
		}
	if(drnkQuant!=0){
		cout<<drnkQuant<<"  #5      "<<drnkTotal<<endl;
		}
	cout<<fixed<<setprecision(2)<<endl;
	cout<<"___________________"<<endl;
	subTotal=(beefTotal+pkbfTotal+veggTotal+gdpgTotal+drnkTotal);
	tax=(subTotal*.12);
// this program is set to the current tax rate implemented by the Philippine Government any changes must also be updated if any
	totalDue=(subTotal+tax);
	cout<<"Subtotal:  "<<subTotal<<endl;
	cout<<"Tax:  "<<tax<<endl;
	cout<<"___________________"<<endl;
	cout<<"Total Due   "<<totalDue<<endl;

Edited 6 Years Ago by kes166: n/a

got a little confused again as i compiled and run the edited version of this one instead of having to stay inside the loop it exits whenever i input an invalid value. hahhaa gonna practice some more bosses

I have some suspicions, but you'll have to post your current code so that we know what we're dealing with.

Edited 6 Years Ago by Fbody: n/a

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()
{
	int choice;
	int beefQuant=0;
	int pkbfQuant=0;
	int veggQuant=0;
	int gdpgQuant=0;
	int drnkQuant=0;
	double subTotal;
	double tax;													//this is double because there are items in the menu that has a decimal value representing cents
	double totalDue;
	double beefTotal=0;
	double pkbfTotal=0;
	double veggTotal=0;
	double gdpgTotal=0;
	double drnkTotal=0;
	
	cout<<"Welcome to Abisado’s Delights"<<endl;
	cout<<"Please choose from the available menu by using the item number on the left"<<endl;
	cout<<endl;
	cout<<"..................................MENU........................................"<<endl;			// this menu as i said in the project description must be updated regularly from the available menu to the price range of each
	cout<<"Item# Description--------------------------------------------------------Price"<<endl;			// the food is kinda odd but nevermind that its just an example
	cout<<"______________________________________________________________________________"<<endl;
	cout<<"[1]Beefy Experience:Beef Teriyaki w/ Rice...............................190.75"<<endl;
	cout<<endl;
	cout<<"[2]Pork and Beef Supreme:Beef Strips w/ Rice and Pork Buns..............160.25"<<endl;
	cout<<endl;
	cout<<"[3]Veggie Surprise:Fresh Salad with Onion Sauerkraut....................125.00"<<endl;
	cout<<endl;
	cout<<"[4]Family Meal:Grilled Pig w/ Rice and Chili Sauce for 12 Servings .....470.00"<<endl;
	cout<<endl;
	cout<<"[5]DRINKS:One-size and free refills......................................85.00"<<endl;
	cout<<endl;

	do{
	cin>>choice;
	switch (choice)
	{
	  case 1:
		beefQuant=beefQuant+1;				//the acronyms i used is a bit odd you can use any acronym you want w/c ever suits you best
		beefTotal=beefQuant*190.75;
		break;
      case 2:
		pkbfQuant=pkbfQuant+1;
		pkbfTotal=pkbfQuant*160.25;
		break;
	  case 3:
		veggQuant=veggQuant+1;
		veggTotal=veggQuant*125.00;
		break;
      case 4:
		gdpgQuant=gdpgQuant+1;
		gdpgTotal=gdpgQuant*470.00;
		break;
	  case 5:
		drnkQuant=drnkQuant+1;
		drnkTotal=drnkQuant*85.00;
		break;
      default:
		cout<<"invalid input"<<endl;
		break;}
		}while(choice>=1&&choice<=5);

	{
    
           system("cls");
		cout<<"You have ordered the following:"<<endl;
		cout<<"___________________"<<choice<<endl;
		if(beefQuant!=0){
			cout<<beefQuant<<"  #1      "<<beefTotal<<endl;
		}
		if(pkbfQuant!=0){
			cout<<pkbfQuant<<"  #2      "<<pkbfTotal<<endl;
		}
		if(veggQuant!=0){
			cout<<veggQuant<<"  #3      "<<veggTotal<<endl;
		}
		if(gdpgQuant!=0){
			cout<<gdpgQuant<<"  #4      "<<gdpgTotal<<endl;
		}
		if(drnkQuant!=0){
			cout<<drnkQuant<<"  #5      "<<drnkTotal<<endl;
		}
		cout<<fixed<<setprecision(2)<<endl;
		cout<<"___________________"<<endl;
		subTotal=(beefTotal+pkbfTotal+veggTotal+gdpgTotal+drnkTotal);
		tax=(subTotal*.12);		                                           	// this program is set to the current tax rate implemented by the Philippine Government any changes must also be updated if any
		totalDue=(subTotal+tax);
		cout<<"Subtotal:  "<<subTotal<<endl;
		cout<<"Tax:  "<<tax<<endl;
		cout<<"___________________"<<endl;
		cout<<"Total Due   "<<totalDue<<endl;
	}
	
		
return 0;
}

hahahaha here's what my teammate did on our project hahaha wth!!!!! nid help

masters nid help with the codes above there's something missing. something's wrong nid help asap

What exactly is missing? I'm guessing you need the menu to display again, but it's not.

HINT: Your loop is still too small, it should start sooner, and end later.

What is there that's so difficult to get? If you're having trouble understanding something, tell us what you don't understand. "I don't get it completely" is a completely worthless statement.

If part of the program needs to repeat, it needs to be in your loop. If it's not repeating, you didn't put it in your loop, figure out how to add it to your loop. It's really that simple.

All you need to do is move the do part of your loop up to an appropriate location, and the while part of the loop down to an appropriate location.

Edited 6 Years Ago by Fbody: n/a

This article has been dead for over six months. Start a new discussion instead.