C/C++ :: Finding Sum Of Values Entered By User In While-loop?

Aug 26, 2014

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


ADVERTISEMENT

Visual C++ :: Using Loop To Take User Input And Keep Running Sum Until 0 Entered

Feb 28, 2013

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++?

View 4 Replies View Related

C++ :: Finding Maximum And Minimum Values Of 10 Numbers Using For Loop

Jan 22, 2013

I want to finding maximum and minimum values of 10 numbers using for loop and the program work wrong !!

#include <iostream>
using namespace std;
int main() {
int x;
int max = -999999999;
int min= 999999999;

[Code] ....

View 2 Replies View Related

C/C++ :: Find Max Number Entered By User And Terminate When Negative Number Entered

Jul 15, 2014

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] ....

View 9 Replies View Related

C/C++ :: Loop Until Alphabet Is Entered?

Dec 4, 2014

im working on our project and this part of the project which says to add a new a room.

Details:

Open the file (ROOMS) that maintains all the ROOMS records.

Ask the user to enter the required data Room_Type and Room_Rate, then save it.

Keep asking the user (Do you want to continue?) until the user enters (N OR n), this should stop the data entry and get the user back to the main menu.

Myproblem :: i keep getting error at the bottom says my while statement is wrong " IntelliSense: no operator "!=" matches these operands"

My other problem:: how do i get back to the main menu?

so what ive done till now is.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
int choice,i=1,Room_rate;
string alphabet;
string Room_type;

[code].....

View 3 Replies View Related

C++ :: Infinite Loop After Char Is Entered?

Nov 17, 2013

I have the program working but when I check if the input to make sure it is not a char it creates a infinite loop. I used an if statement to check for the issue and solve it but its not working. I even tried throwing an exception but I learned later they are not used for things like this.

Code:
#include <iostream>
#include <limits>
#include "contacts.h"
using namespace std;
int main()

[Code].....

View 10 Replies View Related

C/C++ :: Break Out Of Loop When A Certain Word Or Phrase Is Entered

Dec 24, 2014

The code below replaces lowercase characters by upper case and uppercase character by lowercase. Also, I should be able to break out of the loop when I enter 'exit'. It does what it is supposed to do. But I had to come up with a function to break out of 'the while loop'. Is there any shorter or more concise way to break out of the loop when 'exit' is entered?

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

[Code]......

View 5 Replies View Related

C/C++ :: Infinite Loop If Non-numerical Character Entered

Jul 28, 2014

it will produce the answer above..when user enter a nonnumerical character it will force the user to reenter again

do {
cout<<"Min of the secret number : ";
cin>>min;
}while(cin>>min);
cout<<"Max of the secret number : ";
cin>>max;

this is my coding but it will auto jump out when i enter non-numeric character

View 7 Replies View Related

C/C++ :: Do While Loop That Terminates Program When 99999 Is Entered?

Oct 21, 2014

I am trying to do a while loop that terminates the program when 99999 is entered but otherwise allows infinite integers to be entered. My problem is that when a negative number is entered it crashes and also when I enter a number it displays it twice.

#include <stdio.h>
#include <stdlib.h>
main() {
int number;
printf("Input an integer.
"); do {
scanf("%d",&number); /* read a single integer value in */
printf("%d
",number);
} while (number != 99999);
}

View 14 Replies View Related

C/C++ :: Loop That Outputs Until Quit Is Entered For Customer Name

Apr 15, 2015

I was asked to create a loop that outputs until Quit is entered for customer name. This is what my output is suppose to look like: I will also attach the code I made. Im sure there is something wrong with my while command. But I believe there is something else I have to add to print out the last customer name: quit output.

Lab 28 - Your Name

Input Customer Name: xxxxxxxxxx
Input Customer State: xx
Input Product Price: xxx.xx

Customer Name: xxxxxxxxxxx
Customer State: xx
Product Price: xxx.xx
Product Discount: xxx.xx
Discounted Price: xxx.xx
Sales Tax: xx.xx
Total Cost: xxx.xx

Input Customer Name: Quit

End of Lab 28 for Your Name

Code :

#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
double pPrice , pDiscount , dPrice , sTax , tCost ;
int cName , cState ;

[Code] .....

View 4 Replies View Related

C++ :: How Many Entries Entered By The User

Sep 16, 2014

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]...

View 2 Replies View Related

C :: Calculate Number Of Distinct Values Entered Into Array

Sep 12, 2013

I'm trying to calculate the number of distinct values entered into an array. If i enter the followings "3,4,5,6,7,7,6,e (anything that's not a number)" . I get a total of 7 but in reality it should be a 5.

Code:

#include <stdio.h>
//---------function to find the distinct values----
int find_distinct(int list[], int size)
{
int i, j,size2, distinct = 0;
for(i = 0; i < size; i++)

[Code]...

View 9 Replies View Related

C :: How To Make A Switch Case Loop After Input Entered

Dec 31, 2013

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?

View 3 Replies View Related

C :: Checking What User Has Entered (City)

Mar 9, 2013

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.

View 9 Replies View Related

C++ :: How To Use A User Entered File In Fstream

Feb 14, 2014

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.

View 6 Replies View Related

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
--------------------------------------------------------------------------------

View 1 Replies View Related

C++ :: Echo String Entered By User

Oct 3, 2013

/*
* 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

View 3 Replies View Related

C++ :: How To Hide Password Entered By User

Jul 28, 2014

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)

View 10 Replies View Related

C/C++ :: Ignore Strings From Being Entered By User?

Oct 6, 2014

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] ....

View 2 Replies View Related

C :: Error Displaying All Info Entered By User

Mar 4, 2013

Code:

#include<stdio.h>
main() {
int item_code, quantity;
char ans, y;

[Code] ....

View 4 Replies View Related

C++ :: How To Recognize Two Words Entered By User For A String

Feb 11, 2013

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.

View 2 Replies View Related

C/C++ :: Creating Constant At Runtime With User Entered Value?

Aug 14, 2014

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?

View 4 Replies View Related

C/C++ :: Calculate Result Of 2 Numbers That User Entered

Oct 29, 2012

In 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

View 10 Replies View Related

C :: Program To Accept Only Numerical Values And Gives Error If Character Or Symbol Entered

Nov 11, 2013

How can i make my program to accept only numerical values and gives a error notice if a character or a symbol is entered???

View 4 Replies View Related

C :: Find The Largest And Smallest Number Entered By User?

Mar 6, 2015

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] ....

View 4 Replies View Related

C++ :: Find And Delete All Vowels In A Word That Is Entered By User

Mar 26, 2013

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] ....

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved