C++ :: How To Collect Input That Has Been Entered By User
Mar 19, 2013
I am making a program that will suggest meal options when choosing specifics contained within, e.g. style, base, main, sauce.
What I would like to know is how to collect the input that has been entered by the user, say you are given 4 lists and each has an option, how could I chain these together in order to cout a suggestion that is in my database?
-------------------------------------------------------------------------------
Example (not my real Q's and A's):
OUTPUT: What meat would you like?
INPUT: "Beef" //<collect this!
OUTPUT: What sauce would you like?
INPUT: "Tomato" //<and this!
OUTPUT: What would you like to have as the main/base?
INPUT: "Pasta" //<and this!
OUTPUT: I can suggest... "Spaghetti Bolognese" //< and return this from the database using the 3 filters
--------------------------------------------------------------------------------
I am stuck on an exercise where i am supposed to use a loop to take user input and keep a running sum until the user enters a 0. the code i have so far is:
#include <iostream> int main() { using namespace std; int num; int total = 0; int x;
[Code] ....
The full text of the error message is: error c2678:binary'>>':no operator found which takes a left-hand operand of type 'std::istream' . and one more thing i was wondering, is there a difference between c++ and visual c++?
I am trying to find the max number entered by the user, and it should terminate when a negative number is entered. For my code, it will just end when the user inputs a lower number than the previous. i.e.- 10 20 15 "The highest number is 20" when it should be "10 20 5 40 15 -1" "The highest number is 40". No arrays or do/while loops either.
#include <iostream> using namespace std; int Max(int x); int main() { int x;
Program is to add two fractions together like so..
This program adds fractions. ‘Y’ continues, any other key exits program =================================================== Enter numerator 1 ==> 1 Enter denominator 1 ==> 3 Enter numerator 2 ==> 1 Enter denominator 2 ==> 6 1 1 1 --- + --- = --- 3 6 2 ----------------------------------------------------- Continue? Y or N! ==> n
My question is that i need each input to be a number. if a character is entered i want it to output something like..
This program adds fractions. ‘Y’ continues, any other key exits program =================================================== Enter numerator 1 ==> 1 Enter denominator 1 ==> a You need to enter a number here. Press any key to continue.
and then clear the part where the letter was entered.
This program adds fractions. ‘Y’ continues, any other key exits program =================================================== Enter numerator 1 ==> 1 Enter denominator 1 ==>
212Untitled1.cpp[Error] stray '222' in program 212Untitled1.cpp[Error] stray '' in program 212Untitled1.cpp[Error] stray '222' in program 262Untitled1.cpp[Error] stray '222' in program 262Untitled1.cpp[Error] stray '' in program 262Untitled1.cpp[Error] stray '222' in program Untitled1.cppIn function 'int main()': 2125Untitled1.cpp[Error] 'n' was not declared in this scope
I'm making a Project on a Travel Agency and I need to hide the password entered by the user! I am working on Xcode 5.1.1 -> Command Line Tools -> C++ on my MacBook Pro! Here is what I've tried --
string pass =""; char ch; cout << "Enter pass"; ch = getchar(); while(ch != 13){//character 13 is enter
[Code]...
But in the first case the display is -
//Assuming the password is Hello Hello ******
And in the second its giving me 3 errors -
1. Apple Mach-O Linker(Id) Error "_stdscr", referenced from:
2. Apple Mach-O Linker(Id) Error "_wgetch", referenced from:
3. Apple Mach-O Linker(Id) Error clang: error: linker command failed with exit code 1 (use -v to see invocation)
how I can ignore strings from being entered by the user. When the use enter's a string it always evaluates it as even. I though I might use a cin.ignore(); but I am unaware of how to use it.
#include <iostream> using namespace std; int main() { cout << "Enter a number: "; int num = 0;
At the moment I am making program that will use a 2d selection of "cells" to make a "map" of sorts. However, the size will not be known until run time.
I figured using an array would good, because once the size is chosen it won't be changed. However I can't create an array without using a constant.
So the first question is, can I create a constant at run-time with a user entered value that can then be used for an array size? If so, how?
Otherwise, what are my options to achieve this? I know vectors can be used, but A, my compiler keeps giving me problems even when C&P some code bits (yes I even remembered to #include and such) and B, I noticed that vectors reserve extra memory for when the size changes but this is bad (well my dinky little program won't notice, but trying to set good habits as I learn, so I'm keeping it in mind) as I don't need and don't want to allow the size to change after creation.
Which leads to number three, if I do have to use vectors, how can I prevent any accidental size changes after the initial size is determined?
Keep track of the sum of values entered (as well as the smallest and the largest) and the number of values entered. When the loop ends, print the smallest, the largest, the number of values,and the sum of values. Note that to keep the sum, you have to decide on a unit to use for that sum; use cm.
How to find the largest and smallest number entered by a user. So far I'm able to add, find the average and count how many numbers are entered.
I'm just having trouble with find the max and min. I tried if statements and it breaks the program will it wont let me exit the while loop or the program will do a force close after entering a value.
Code:
#include <stdio.h> #include <stdlib.h> int main(){
int maxNum=0, minNum=0, value, count=0, sum=0; double average;
The program should find and delete all vowels in a word that is user entered. This is what I have so far and I know it should be essentially this format I just don't know how to set enteredword and word equal to each other.
#include <string> #include <iostream> using namespace std; void vowelremover(string&); int main () { string word;
I am trying to make a program with a Cartesian class that allows the user to enter 2 coordinates and displays these coordinates. When I try to compile it, I get a message saying the x and y in x=c and y=d don't name a type. How can I fix this? Also, how would I go about inserting an assignment function that assigns the values of coord1 to coord2?
Code: #include <iostream> #include <istream> #include <ostream> using namespace std; class Cartesian { private: double x; double y;
I would like to know the algorithm or flow for finding unequal elements in an array entered by user. I tried using for loop but didn't get the expected output
Code: #include <iostream> #include <string> using namespace std; int main() { int a[10],b[10]; //array of integer elements
The program should find and delete all vowels in a word that is user entered. This is what I have so far and I know it should be essentially this format I just don't know how to set entered word and word equal to each other.
Code:
#include <string> #include <iostream> using namespace std; void vowelremover(string&); string word; int main () {//string word;
I'm working on a code that needs to loop a switch case back to the beginning after a certain input is entered.
ex) Code:
printf("Select an option); printf("1. Play game"); printf("2. Status"); printf("3. Exit"); scanf("%i", &userinput); switch(userinput);
[Code]...
For my program, I want option 2 to display something, then loop back to "select and option" after the user presses enter. How would I write that? Would i use a while? do while?