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


ADVERTISEMENT

Visual C++ :: Program That Take Input From A User And Calculate It In A Do While Loop

May 15, 2013

I'm trying to create a program that will take input from a user and calculate it in a do-while loop. The program does the calculation but the answer is wrong. The loop also doesn't work. The purpose of the program is to see how much an item will cost after a discount is taken off and tax is added.

#include <iostream>
#include <cmath>
using namespace std;
double original_cost;
double discount;
double tax;
double total;
char answer;

[Code]...

View 2 Replies View Related

C++ :: Take Argument From User - Loop Only Running Once

Apr 14, 2013

This program is meant as practice. However, it is not working as intended. The for loop is meant to take the argument from the user and use it as the amount of times to loop. Instead it simply outputting: . It is supposed to output i++ but does not.

Here is the code:

main.cpp:
#include <iostream>
#include <stdlib.h>
int main(int main, char* arg[], char* arg2[]) {
int iterator = atoi(arg2[0]);
std::string z = "-c";

[Code] ....

View 19 Replies View Related

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

Visual C++ :: How To Retrieve Window Proc In Process Running In Other User

Apr 25, 2014

I am encountering a problem on retrieving the Window Proc of a window that running in a process with another user.

For example, I have logon windows with domainuser1, and run the following command as:

runas /profile /env /user:domainuser2 C:WindowsSystem32calc.exe

And then the Calculator is shown in domainuser1 desktop, but the process is running in domainuser2 account.

When running Spy++ (either wither domainuser1 or domainuser2) to view the calculator window, the Windoe Proc field is shown 'Unavailable' I also try to call GetWindowLong against this window, it will always returns NULL.

I am just wondering if it is possible to retrieve the Window Proc of the window running in a process of another account, is is possible?

View 9 Replies View Related

C++ :: User Input - Infinite While Loop

Sep 5, 2014

I have a small loop that gets the user input, as well as acts as input validation to make sure he or she doesn't enter a value that is not within the specified range.

The user is supposed to enter a month number. E.g. if he or she chooses February, then enter 2, or December, 12.

It works correctly if they type a number that is not in the range, but goes into an infinite loop if, say, they type a string such as "month".

Code:
int main() {
// Variable Declaration(s)/Initialization(s)
int month=0;

// Get input
cout<<"Enter a month";
cin>>month;

[Code] ....

How could I go about revising this?

View 4 Replies View Related

C++ :: Loop Not Working User Input?

Jan 20, 2013

Some of my loop is not working. How messed up is this code.. Commented non working code

// ADIT.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include "windows.h"

[Code]....

View 3 Replies View Related

C++ :: Loop Depending On User Input

Jul 31, 2013

I'm trying to get this program to loop the number of times I get it to input. The program compiles alright, and it does loop when I tell it too, but how do I output the grades of the multiple students?

#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
int weighted1 = 0;
int weighted2 = 0;

[Code] .....

View 12 Replies View Related

C++ :: While Loop Keeps Looping Without Getting Input From User

Dec 5, 2013

struct stu_dat //outside main function
{
int rollno;
char name[45],
float average;

[Code] ....

No compilation problem.when executing prompt waits for inputting rollno, but, as soon as i enter a char string it keeps looping displaying the "want to enter more data?".i cant understand what is going on,as there is no compilation problem and runs good till i input the name.

View 3 Replies View Related

C++ :: Indefinite User Input Loop?

Dec 13, 2014

In short, I'm trying to make a CLI for a project that can take multiple user inputs add I don't exactly know what I'm doing. I'm able to get cin to take one user input, but that's all I'm sure about.

View 8 Replies View Related

C/C++ :: While / For Loop User Input Sentence

Sep 15, 2014

I'm not sure what the program's purpose is?

1) Ask the user to enter a sentence. Until you reach the end of the sentence, test each character to count the number of spaces and letters.

2) For every space counted, print "SPACE", then print one "!" for every letter counted on an indented line underneath the "SPACE".

Your test sentence to use is: "The potash feldspars are important rock-forming minerals in plutonic, volcanic, and metamorphic rocks."

HINT: You do not need any strings. You need one while loop and two for loops. <cctype>

View 4 Replies View Related

C :: Unscramble User Input - Error In Loop

Sep 24, 2014

The purpose of this program is to unscramble the user's input. for example if the user entered 'ftooabll' the program would print 'football'. find the error that I am making....

Now, this only works for strings that are contained in the file wordlist. That being said, I would like this to repeat this search multiple times. Currently, the process is being repeated 7 times, but it only works on the first iteration. The code and sample input/output is below.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUMLOOP 6
void sort_string(char*);

[Code] ....

Sample input/output: (note: all data has been verified to be in the wordlist)

Enter string:
4132dcba
abcd1234
Enter string:
4132dcba
Enter string:
4132dcba
Enter string:
4132dcba
Enter string:
4132dcba
Enter string:
4132dcba
Enter string:
4132dcba

View 3 Replies View Related

C :: Fixing User Input Errors In A For Loop

Mar 6, 2015

So I have to write a step in my program that reads in up to 8 variables. Simple, but if the User submits an invalid value, I have to give an error message and ask him to re-enter the value until he enters a valid number. Here's my while loop that works perfectly:

Code:

while (true) {
printf("
Enter the mark given by Judge 1: ");
scanf("%f", &m1);
if ((m1 >= 0.0) && (m1 <= 10.0)) {
break;
}

[code]...

I'm not sure what to write in the else statement to make the programme understand that it has to repeat the exact same step but without adding 1 to index. Is this possible or do I have to suck it up and just use while loops instead? I'm very new to programming.

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++ :: For Loop - Display Smallest And Largest Numbers From User Input

Jul 29, 2013

I'm suppose to write a program using (for loop) that asks the user to enter any amount of numbers, so that it can display the smallest and largest. My program successfully finds the largest, but it is always displaying 0 for the smallest, I think Im doing something wrong with the internalization but I dont know what to change it to.

This is what I have ....

#include <iostream>
using namespace std;
int main() {
int amount;
int count;
int number = 0;
int smallest = 0;
int largest = 0;
cout << "Enter total numbers to process: ";

[Code] ....

View 4 Replies View Related

C++ :: Program To Allow A User To Input A Number From Keyboard That Involves Loop Not Working Right?

Mar 30, 2014

I'm trying to write a C++ program that will allow a user to input a number from the keyboard. Then using a loop, that will perform 10 times, multiply the entered number by the loop counter. Print out the loop counter, the entered number and the product of the loop counter and the entered number. A one-time heading should be displayed before information is printed.

This kinda of what I have so far:

#include <iosteam>
using namespace std;
int main () {
Start
Declare: numScores, sum, score, avg, SENTINEL = 200
numScores = 0

[Code] ....

All the programs I have tried to make are not working?

View 4 Replies View Related

C++ :: Delete Invalid Input Until Correct Input Is Entered?

Mar 20, 2014

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

View 5 Replies View Related

Visual C++ :: Re-input Variables After Loop Ended

Oct 18, 2014

I just started programming and want to make the game cows and bulls. The problem is that after the loop has ended and both vectors are not the same I want the user to 're-input' the starting variables a,b,c&d but I don't know how to.

Code:
#include "std_lib_facilities.h"
int comparison(int a, int b, int c, int d)
{
vector<int>bc={ 1, 2, 4, 9 };

[Code].....

View 2 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++ :: How To Prevent Loop Running Over

Feb 18, 2014

i am writing a function that takes a delimited string and splits the strings into it's respective words according to the delimeter.

1) iterate through string and store delimeter position in vector array.

2) iterate through again and use substr to split into words and store again in a vector.

I then have a dictionary file, and am comapring each values in the string with each in the dictionary, problem is that it overruns the loop and obviously gives a subscript out of range error.

Code:
#include <iostream>#include <fstream>
#include <vector>
using namespace std;
//Start with string inputString
//Find delimeters ::pos as ints and stores positions in vector <int> array
//Run though string using 'find' and seperate string by positions of char32s
//Build vector<string> array of individual words in string
//Open dictionary file and loop though testing each words in vector string array against each word in dictionary

[code]....

View 4 Replies View Related

C++ :: Loop Is Running Infinitely

Aug 7, 2014

My program is supposed to end when both a and b are 1. Where it is wrong.

Code:
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int roll()

[Code] ....

View 2 Replies View Related

Visual C++ :: Allowing User To Input Decimal?

Oct 21, 2013

This code is near complete, the only task that is left is allowing the user to input a decimal and then two integers, or automatically using .00 decimal.

The automatic part: /*This is not correct.

printf(".%.2d
", number);
*/

But that does no good for me. Question: Do I have to create a some sort of while loop again, to allow the user to input a decimal followed by integer?

Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
int j , i = 0, k = 0;
int number;

[code]....

View 1 Replies View Related

Visual C++ :: Taking Decimal Input From The User

Feb 21, 2015

I want the input for the price in decimal format(15.00). If the input is in integer format then I want to convert it to decimal format.

The maximum price for a sale is 999.99 and minimum is 0.00.

I have tried so far:

Code:
#include<iostream>
using std::cout;
using std::cin;
void main(){
float eventPrice;

[Code] .....

A valid input will be:

1.8,
0.8,
0.00,
0,
9,
99

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







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