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


ADVERTISEMENT

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/C++ :: Do While Loop Not Working - Exits After Input

Feb 6, 2014

My code:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int factorial(int n);
int main() {
int n,num;
do {

[Code] ....

My while loop is not working... it exits after 1 input...

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

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

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++ :: 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++ :: While Loop Condition Not Working Correctly

Dec 8, 2014

The while loop part of my program isn't working right. stringOriginal is an array. If a large amount of characters passed the max 80 im processing is typed, it goes into a infinite loop. Also the condition doesn't work i type in quit and the loop continues.

while(stringOriginal != "quit"){
std::cout << "Enter a string of characters you would like to reverse
";
cin.getline(stringOriginal,79,'
');
}

View 1 Replies View Related

C :: While Loop Not Working - Not Sure Whether Fflush Or Scanf Is Used Correctly

Jan 17, 2015

I just started learning programming. I tried using this but the loop is not working ....

Code:
#include<stdio.h>
#include<ctype.h>
#define PI 3.1416
void main(void) {
char choice;
float r, area;

[Code] ....

However when i removed this portion below, and replacing it with choice='Y';, the loop works just fine although my intention is to continue the loop only when 'y' is entered.

Code:
printf("Continue? Y/N:");
fflush(stdin);
scanf_s("%c", &choice);
choice = toupper(choice);

I think that I'm using the code wrongly but i'm not sure where the mistake lies in

View 8 Replies View Related

C++ :: Allow User To Select Arbitrary File From Working Directory?

Apr 28, 2014

I know how to open a specific files by using

ifstream infile("something.txt");

but how do you let the user select an arbitrary file from the working directory?

View 12 Replies View Related

C++ :: Need To Enter More Than One Char Input Not Working

Jan 23, 2015

Basically I'm having trouble reading more than one character.I want the user to input character traits(ie, w, a), if two traits are entered they get the job.

But I cannot get my program to read more than one character input.

This is what I have so far...

#include <iostream>
using namespace std;
int main(){
char input;
int count = 0;

[Code] .....

View 6 Replies View Related

C++ :: User Array Size And Sorting User Input

Nov 1, 2014

I am making program that allows the user to determine how big the array size will be and then asks the user to make up numbers to fill the array. Every time run the program on Dev C++ it says "program has stopped working"

Heres My Code:

//Assignment 19 Program 2
#include <iostream>
using namespace std;
int main()

[Code].....

View 3 Replies View Related

C++ :: Input / Output Text File Manipulation Not Working

Mar 24, 2013

Why my output screen for this program does not want to stay open. It only opens for a split of a second and it's gone. The program is supposed to take numbers from a input file and display and save the manipulation in the output file. Here is the program.

Code:
#include<iostream>
#include<fstream>
#include<iomanip>
usingnamespace std;

[Code] ....

View 6 Replies View Related

C++ :: Printing Double Triangle - Working Fine Up To Input 7

Feb 22, 2013

I wrote code for printing a double triangle. Its woking fine upto input is 7. but when the input is 8 the output is disturbed. the code is this.

#include<iostream>
using namespace std;
int main() {
int a;
cout<<"Enter a number"<<endl;

[Code] ....

View 3 Replies View Related

C++ :: Queues Program Suddenly Stops Working When Input Value

Feb 22, 2013

I'm having troubles with this program I made. Put it simply, it's a basic program using Queues. Whenever I try to input a value, my compiler(Dev C) suddenly stops working. The .exe file crashes and I've no way on how I can execute my program.

Code :
#include<iostream>
using namespace std;
int *queue;
int rear, front, queueSize;
void enqueue();
void dequeue();
void display();

[Code] ....

View 1 Replies View Related

C++ :: Creating List Of Medical Resources And Their Attributes - Input To Structure Array Not Working?

Mar 23, 2014

I wrote this program to create a list of medical resources and their attributes, a task I have been performing repeatedly lately. I'm still fairly new to C++, so I thought to create a structure "Resource", and then an array of those structures "city[300]". My problem is that the input doesn't seem to be happening: the program runs, but when it prints to screen/writes to the file at the end, all the shows is:

Resource Type:
Name:
Address:
Phone:
Website:

for every resource that was input. All the fields are blank.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct Resource {
string typeID;
string name;

[Code] ....

View 1 Replies View Related

C :: The Last User Entry In Loop Fprintfed Twice?

Apr 13, 2014

Still working on my first homegrown C program design . The function basically allows the user to enter a list of classes and grades and saves the list to a file to be used later in the file. The function compiles and runs through without error except for the fact that it always prints the last user entry to the *profilep file twice. Just as a note, the scanchar function is one I made to scan in one character and an end of line character to throw away the end of line char before I learned about %*c about 30 minutes ago...

Also I haven't much bothered to strengthen the function against crazy user input but I have heard using fgets and sscanf in conjunction can replace scanf and protect against weird user input. How to apply this within the program.

Code:
// creates a new profile and prints it to the profile file.
void newprof(FILE* profilep, const char *allclasses[ABBR_SIZE]){
int c, checker, counter;
int i, a;
char prof[MAX_PROF][ABBR_SIZE];
char grades[MAX_PROF][3];

[Code] .....

View 1 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++ :: While Loop Keeps Asking For Input After EOF

May 11, 2013

This is an example from C++ Primer on while loops shortened for simplicity:

int main() {
int value = 0;
while(cin >> value) cout << value;
return 0;
}

When I compile and run the above code the program keeps asking for input after I input nothing but pressing ENTER no matter how many times. The only way I can get it to stop asking for input is to input something other than an int such as a char or string. Program executes as intended after that. I have googled this issue and read all seemingly relevant results and nothing seems to pertain to my exact problem. I think it may have something to do with my computer's own settings or something and am baffled as to what it may be.

View 10 Replies View Related

C++ ::  How To Make A Loop Until User Asks To Break

Apr 4, 2013

I'm making a program for a MMO I play. It calculates the cash and resources needed to build certain 'modules'. I'm having trouble to do something very simple : make a loop until the user asks to break the loop. Here is what the interface looks like :

What module do you want to install?

(Examples: 'Avenger' or 'VLLT')

dd // I input this
DD. COST each : 60,000 cr.

How many do you want? (Modules left:15)
(NOTE : You may enter a negative number if you made a mistake)
3 // I input this
Current Total Module Price : 180000 cr
+6 droids

[Code] ....

The bigger code box below is a part of the code I made. What I deleted is uninteresting, it's just the same thing again : other resources, other 'modules'...

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
struct resources// Defines the amount of resources and their price

[Code] ....

View 8 Replies View Related







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