C++ :: Program With Do-while Loop To Restart Program And Validation

May 11, 2013

I am having problems at the end of the program with the do-while loop to restart the program and the validation.

#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <time.h>
using namespace std;

[code]....

View 3 Replies


ADVERTISEMENT

C :: Use A Loop To Restart A Program

Feb 21, 2015

I've just started to learn C programming. In following program I need to use a loop, so at the end, it asks the user that if wants to try other numbers or not. If yes program restarts from beginning.

Code:
/*
A program who checks three positive integers to be 3 sides of a triangle and calculates the area and shows the triangle type.
*/

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)

[Code] .....

View 11 Replies View Related

C/C++ :: Yes Or No To Restart A Program Or End It

Aug 8, 2014

I just started learning c++ and got a problem now, i need a Y/N code, i case of yes the loop will restart and i case of no the program will end, Heres the code i got so far from trying to make my first steps.

#include <stdio.h>
void main() {
int a,b,c;
printf ("Zahl 1 Eingeben
");
scanf ("%i",&a);

[Code] ....

As u can see the other printf tasks are in german, but they are not important, the last one needs a Y/N "switch" y to restart the loop, and n to stop the program.

View 2 Replies View Related

C :: If Put WRONG Input For INTEGER / Program Will Restart

Feb 15, 2015

I have a question about my program.. I would like to make a program that if you put "ABC" on INT, the program will restart again... below are my coding...but it not works..if i put ABC on INT, the "Invalid Mark.. please re-insert mark :" will repeat, repeat and repeat infinitely...

Code:

#include <stdio.h>
void calcul() {int mark;
char * grade;
if (!(scanf("%d",&mark))){printf("
}

[code]....

View 7 Replies View Related

C++ :: Restart Program Every Time Type Move Of Blank Place?

Mar 5, 2013

I have to make a 8-puzzle and I got the algorithm i just dont know how to restart the program every time i type the move of the blank place in the 3x3 puzzle so i dont have to make 10000 lines to solve the puzzle

View 2 Replies View Related

C++ :: Game Loop Design - Restart Round?

Sep 30, 2013

I have a simple game loop.

while(true) {
//round initialization stuff
while(true) {
//capture input, make pieces move,
}
}

I am faced with the decision of what is the best way of restarting the game. The problem is, the condition for restarting a game is very, very deep inside the game's logic. So returning returning... is not an option, or at least, it ain't gonna be pretty.

So one of my considerations is to use a goto label, like so:

while(true) {
//round initialization stuff
while(true) {
//capture input, make pieces move,
} restart_round:
}

This seems to be the cleanest solution, since it allows me to fully reset the 'state' of the round, by first having all the destructors(pertaining to the round's objects) called, and then the constructors and other initialisation stuff.

Are there any subtleties that I am missing regarding this solution?

View 10 Replies View Related

C++ :: Program To Check Validation Of Functions

Apr 12, 2013

I'm writing a program to check whether codes from a file are invalid, valid, inactive, or valid and active, but can't get it to work properly. The invalid codes are being found, but the other three are not. I think it may have something to do with my "active" function.

#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
using namespace std;

struct ActiveCodes {
string code;
bool flag;

[Code] ....

View 19 Replies View Related

C++ :: Input Validation - Program Cannot Accept Negative Numbers

Nov 12, 2014

#include <iostream>
#include <iomanip>
using namespace std;

// Function Prototype
void sortArray(int array[], int size);

[Code] ....

This program was made to allow students to enter as many test scores as they want and the program will show them in ascending order and then will calculate the average of all test scores. It works wonderful until you enter a negative test score and then it throws the averaging process off. I can't seem to be able to make the program not accept the negative numbers.

View 1 Replies View Related

C++ :: Input Validation In For Loop

Aug 14, 2014

// PROBLEM - Use INPUT VALIDATION so number entered is positive. I can't get it to work

#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, const char * argv[]) {
// SUM OF NUMBERS
// Enter a positive integer

[Code] ....

View 2 Replies View Related

C :: Loop Does Not Work And Program Quits Without Displaying For Loop Function

Oct 13, 2014

We are making a program--but every time we input a value for scanf, the following for loop does not work and the program quits without displaying the for loop's function. We are not getting any errors.

View 11 Replies View Related

C :: Validation Loop - Displays Error Message When Input Is Outside The Range

May 14, 2013

I am trying to get this simple validation loop to work so that it only displays the error message when the input is outside the range 1-3. yet it always seems to display the message.

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

int Menu ();
int ValidInt(int , int );

[Code] ....

View 5 Replies View Related

C++ :: Creating Do-While Loop In Program

Apr 28, 2014

I need starting a do-while loop in my program that runs up to 10 time that asks the user to enter up to 10 scores, which include the slope and rating for the course, and calculates the handicap for each score.

Here's what I have so far:

Code:
{
//This program calculates a golfers handicap.
#include <iostream>
#include <string>
using namespace std;

[Code] ....

View 1 Replies View Related

C :: Simple Loop Program?

Feb 27, 2014

3. Write a program that reads a sequence of positive integers and prints out their sum, except that if the same number occurs several times consecutively, ignore all but the first. Assume an input of 0 marks the end of the input. For example, if the input is 3 8 5 5 4 9 1 1 1 1 8 0 then you should print 38 (i.e., ignore one of the 5's and three of the 1's).

View 5 Replies View Related

C :: Make A Program Using While Or For Loop?

Nov 20, 2014

I'm trying to write a program for a lab, I know how easy it is but cant see to crack it.

I need to make a program using while or for loop.

I must have the user type a number, for an input value an output value but then do it again several times but without it going on forever asking again and again.

View 4 Replies View Related

C++ :: How To Make A Loop So Program Never End

Aug 29, 2014

How to make a loop so program never end, it end only by typing "EXIT"

View 1 Replies View Related

C++ :: Program To Enter Limit Of A Loop

Feb 20, 2013

I need a program in c++ that will enter a limit of the loop. using nested for loop with a limit of 3 loops only.

like this !

for (){
for (){
for (){
cout
}
}
}

Sample output:
Enter a number : 3 [enter]

1 2 3
4 5 6
7 8 9

2 3 4
5 6 7
8 9 10

3 4 5
6 7 8
9 10 11

View 2 Replies View Related

C/C++ :: Infinite For Loop - Program Just Closes

Feb 10, 2015

So I learned how to make a basic for loop and I decided to try my best to make an infinite one. Every time I run it, it doesn't say anything and just closes. Visual Studio doesn't say there's anything wrong with my code.

Here's the code

#include <iostream>
#include <conio.h>
using namespace std;
int main () {
int d = 9;
for(int k = 10; k < d; k = k +1) {
cout << "For loop value = " << k << endl;
getch();
} }

View 4 Replies View Related

C/C++ :: How To Loop A Program Back To Beginning

Mar 4, 2014

I was asked by my teacher to create while loop for this, iv have completely for gotten how and all the tutorial that i have found show basic lopping.

#include <iostream>
#include <iomanip>
using namespace std;
void checkAnswers(char[], char[], int, int);
int main(int argc, const char * argv[]) {
int choice = 0;
const int num_question=20;
const int min_correct=15;
char answers[num_question] ={

[Code] ....

View 5 Replies View Related

C++ :: Cab Company Program / Endless Loop?

Jan 14, 2015

I'm trying to get this program to return total taxi cab fair an infinite number of times, however, when I use the while statement after for and try to run the program, it just keeps displaying the first total fair rapidly.

specifications:A cab company needs a program to calculate the cost of a cab ride.

The driver will enter the length of the trip in miles.

The miles entered must be greater than 0.

Create a function to calculate the charge. The function should receive one argument, the length of the trip, and should return the total fare for the ride.

The taxi charges a fixed charge of $2.50, plus an additional charge of $1.85 per mile.

Allow the user to calculate any number of trips.

At the end display the total of all the fares.

here is my code:

#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes
double getLength ();
int main () {

[code]....

View 3 Replies View Related

C++ :: Decipher Program - Nested Loop

Feb 17, 2013

I'm writing a series of basic decipher programs and I have run into an issue where I get the correct answer when I start the loops at the iteration that contains the correct answer.

Code:
// generate key "words" with length of 3
for (int x = 0; x < 26; x++){
for (int y = 0; y < 26; y++){
for (int z = 0; z < 26; z++){

[Code] ....

This is the essence of the loop, I've attached the program in its entirety if necessary. Basically what happens is if I start the loops at x = 17, y = 7, z = 12, then I get the correct decipher shifts but if I start at 0,0,0 whenever it gets to that iteration (12,000 ish) the shifts are off by 2 or 3. "koq" should translate to "the" but im getting "dcz". Is this a simple bug in the or is something moving to fast for something else to keep up?

l3_ws.txt
main.cpp

View 1 Replies View Related

C :: Make A Program That Multiplies Loop Variable By 2

Nov 15, 2013

I have an exam in C programming I'm a little stuck on loops..I have to make a program that multiplies the loop variable by 2 then takes away 1... easy, that was a for loop no problem

for (x=3; x<=65; x=x*2-1)

that should print out 3 5 9 17 33 65 however, my lecturer has given the task for it to reverse, but not to display the number 17 on the way back down using an if statement...however, this time it must be a do while loop... This is what I have so far.

Code:

#include <stdio.h>
#include <stdlib.h>
int main()
{
int x = 129;
}

[code]....

View 7 Replies View Related

C :: Program To Calculate Factorial Of Numbers - For Loop

Feb 5, 2013

I have been working on a program to calculate the factorial of numbers. Part of my code is copied and modified from the FAQ about validating numbers in user input.

I have encountered a problem with the for loop that I am using near the end of my code. No matter what I do, it seems that my loop only does the multiplication of b = a*(a-1) and then prints. For example, inputting 5 will result in a print of 20, but the factorial is 120.

Code:
int main(void) {
char buf[BUFSIZ];
char *p;
long int a;
long int b;
long int i;

printf ("Enter a number to be factorialized: ");

[Code] ....

View 5 Replies View Related

C++ :: How To Use While Loop To Control Sudden Termination Program

Jan 4, 2013

how to use while loop to control sudden termination program of win32 console application ?

View 1 Replies View Related

C++ :: Program To Generate Random Number Between 1 To 100 - While Loop Will Not End

Feb 21, 2014

My program asks me to write a C++ program that generates a random number between 1-100, and lets the user guess the number until he/she guesses correctly.

I have every thing done but my loop will not end. I know I have to "update" the loop to end it but I don't know what that means.

#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;

int main() {
srand(time(NULL)); //the function that generates random numbers

[Code] .....

View 2 Replies View Related

C++ :: For Loop Theory For Tile Map Editing Program

Jul 10, 2013

Basically I have an tile class with the following variables: x, y, texture, and solid. I have created an array called tile MAP[map_tiles_x][map_tiles_y]. The object of the following snip-it of code is to loop through all of the tiles in the map placing their default values in each. For some reason this code does not work as planned, but in theory shouldn't it? I cannot see why it doesn't work. (BTW I do plan on open sourcing this map editor.

void init_map(){
for (int tile_y; tile_y < map_tiles_y; tile_y++){
for (int tile_x; tile_x < map_tiles_x; tile_x++){
MAP[tile_x][tile_y].x = tile_x * tile_size;
MAP[tile_x][tile_y].y = tile_y * tile_size;
MAP[tile_x][tile_y].solid = false;
std::cout << MAP[tile_x][tile_y].x << ", " << MAP[tile_x][tile_y].y;
} }

I should also add the effect of the code. Basically it only sets the default coordinates for the first object :/.

View 4 Replies View Related

C++ :: Infinite Loop When Program Generates New Bracket

Feb 14, 2014

I am getting an infinite loop when my program generates a new bracket

#include <iostream>
#include <string>
#include <stdlib.h>
#include <numeric>
#include <fstream>
#include <vector>
using namespace std;
const int MAXTEAMS = 20;
const char* c;

[Code] ....

View 2 Replies View Related







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