C :: Error Displaying All Info Entered By User
Mar 4, 2013Code:
#include<stdio.h>
main() {
int item_code, quantity;
char ans, y;
[Code] ....
Code:
#include<stdio.h>
main() {
int item_code, quantity;
char ans, y;
[Code] ....
So I have an array of my own class, "Restaurant," but I'm having a hard time figuring out how to store the info entered by the user into the array.
In total, I have two classes. I will show you all I have, it's a lot but I know it will be easier to understand.
My problem is in the AddRestaurant(), since that is where I should ask the user for all the information and store it in the array.
Also consider that I have to use the FTime class as well to handle the time. Basically I want to do something like this:
info[count].SetRating();
which will put the rating part of the class Restaurant into the array[count]
Also, my program doesn't compile because of the AddRestaurant and PrintAll functions since what I am showing is what I want to do, not what works.
//main.cpp
#include <iostream>
#include <iomanip>
#include <string>
#include "Restaurant.h"
#include "FTime.h"
int ReadMenuChoice();
[Code] .....
I have an if statement that should either match a text variable that the user has entered and a another text variable that has been got from an array but they won't match even if they are the same,Im at a lost with it.
void displayQuestion(int noQuestion, string questionArray[], string answerarray[], string answer, double scorearray, double finalscore){
cout << questionArray[noQuestion] << endl;
cout << "enter an answer " << endl;
cin >> answer;
[Code] ....
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;
[Code] ....
What I want to do is create a file that will ask the user to enter his info,n then store it in a text file The screen will ask the user if he wants to update his info. if he says yes then the screen will be cleared and the old info will be printed on the screen. The user will enter his new info that will be stored in a new file. My problem is that once the user finishes entering his input the program just closes D: and the rest of the program won't run.
Code:
int main()
{
string ans;
ofstream Xfile("original.txt");
cout <<"Enter your name and address please"<<endl;
cout<<"Press Ctrl+Z+Enter when you are done"<<endl;
string name_and_street;
[Code]...
I was looking at this code:
private void button1_Click(object sender, EventArgs e)
{
string input = textBox3.Text;
[Code].....
And how to rewrite the code so that it display the MySQL table data for a specific user I already have a string called username and that stores the username entered on the login form. I want the code to use the username string to search for the name and display that users info.
My table contents are: username
First name
Last name
Position
Employee Id
Airline
when i declare local variable x and use it in array,the error is occure that use of un assign local variable.
namespace ConsoleApplication11
{class Program
{
static void Main(string[] args)
{
int x;
Console.Write("enter how many entries you want");
[Code]...
I am using Dev C++ on a windows computer.
In my code, the user enters the name of a city, and then according to what city it is, the program displays the coordinates of that city
I can't find a way of figuring out and checking which city the user has entered so the code can displays its appropriate latitude and longitude.
So, I am making a name-database-type-thing and I want the user to be able to enter there own file. Like, here:
string fileName;
string name;
cout<<"What is your file name?"<<endl;
getline(cin, fileName);
ifstream nameFile(fileName);
getline(cin, name);
nameFile<<"Name: "<<endl;
Well, that last part is in a loop, so you can enter an unlimited number of names to the .txt file.
So, it won't let me use the string in ifstream. How can I fix this? This maybe unclear, so if it is just say so and I will edit it.
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
--------------------------------------------------------------------------------
/*
* echoString2.c
* Echoes a string entered by user. Converts input to C-style string.
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main(void) {
char aString[200];
char *stringPtr = aString;
[Code] ....
and these are my errors
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;
[Code] ....
In my little experiment i am trying to get the compiler to recognize 1 word with 2 parts from a list of names.
For example: if the user wanted to choose "candy bar", from a list of items which include: "candy bar", "cat", "dog"
My current code can recognize words without a space like cat and dog. But how can i recognize candy bar?
I tried using getline but its of no use.
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.
View 9 Replies View RelatedIn this exercise, write a rational number calculator that ask the user to enter two rational number:
a/b + c/d
and produce the result:
(ad+bc)/bd
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;
[Code] ....
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;
[Code] ....
exercise in c: write a program which calculates % of even numbers entered by a user in an array;
1) check if user hasn't entered float value; if has issue warning;
2) give the option for user to press "stop" to exit program any time.
int c,sk[100],i,sum1=0, sum2=0, rel;
printf ("How many numbers will you enter?
");
scanf ("%d", &c);
printf ("Enter %d numbers (to exit program press - stop)
", c);
[Code] ....
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;
[Code] ....
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
[Code] ....
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++?
So I have a program where I solve a maze using stacks. So my display_maze function take two parameters and displays the maze according to where the x coordinate and y coordinate are.
I have an error during my move function, as my maze doesn't display for some reason
void Player::player_move() {
Stack stack;
Maze maze;
Lock taken;
// Monster monster;
stack.push_values();
[Code] ....
It should be displaying, because after debugging I discovered the problem isn't with the display_maze function.
I would like to get user input of some parameters value (mostly of type "double", but few of type "int") but displaying the default value at the place of input. If the user does not want to modify the value, he types "Enter" to pass; if the use wants to modify the value, he enters a new value at the place of the value by default, then types "Enter" to pass to the next parameter.
Here is a simplified example:
int main() {
double a = 1.5;
double b = 2.5;
double c = 3.5;
double x;
[code]...
However, this does not work. getline() cannot take double type, and I do not know whether the rest of the code is good and efficient.
I need to have a program display an error message if the variable entered isn't an integer but then I want it to cin again. I have this but it doesn't work:
cout << "Enter an Integer: " ;
for (;;) {
cin >> var;
if (!cin) {
[Code] ....
I am not sure how to do what I want and this doesn't work, it just repeats That wasn't an int.. over and over again.