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)
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.
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.
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...
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
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:
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?
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 <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.
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.
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.
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;
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).
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.
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(); } }
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 () {
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?
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; }
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;
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
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.