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.
I have tried to submit this topic before but i didn't submit my whole code and it was removed. So here it is. All I am trying to do is load form2 from form1 then back to form1 from form2 for a certain number of times the get out of the loop. I am new to C-Sharp and it seems as though I cant seem to figure out a way to do this.
Here is form1 and form2 code. I have commented out a few things I have tried.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;
"Write a program to gauge the rate of inflation for the past year. The program asks for the price of an item (such as a hot dog or a 1-carat diamond) both one year ago and today. It estimates the inflation rate as the difference in price divided by the year-ago price. Your program should allow the user to repeat this calculation as often as the user wishes. Define a function to compute the rate of inflation. The inflation rate should be a value of type double giving the rate as a percent, for example 5.3 for 5.3 percent.
Your program must use a function to compute the rate of inflation. A program which does not use a function will be awarded a score of zero, even if all tests pass."
So far I've got the code below. It runs, but it outputs zero for the inflation (no matter how values I enter for the prices) and does not stop running when I enter zero.
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;
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)
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 am writing another program and I cannot find for the life of me how to loop the program back to the start of a function.
Code: #include <stdio.h> #include <stdlib.h> int main(void) { int choice; char band1, band2, band3, band4; printf ("This program calculates the resistor value based on the colours of the wire. (enter the integer near the command) "); printf ("What would you like to do?
[Code].....
This is my current iteration of the program. Obviously, I haven't finished writing the case 1 of the first switch, but for the other ones. I thought that return main would cause the program to loop back to the beginning after executing the case, but I see that it is not the case (pun not intended). Anyways, what would I have to insert to cause the program to loop again (other than for case 3)? And another question, why is it that in scanf in the first case, the program only accepts two characters before finishing?
I am working on a problem that requires a nest for loop to be converted to a recursive function. I am going to provide just the code instead of the entire program.
Code:
for (R1=1; R1 <+3, R1++){ //for loop printf (something); } // the recursive function void loopR1 (int R1, int max){ if (R1 <= max){ printf (something);
[Code]...
when calling the recursive function in main i am using the following statement...
I am writing a program with a function that includes a long loop. I need this function to return a value when each loop is done, to send this value to output, in order to follow the progression. But I don't know how to do it in easy way. The function is like follow:
int goC(){ ... // some local value definition for(int i = 0; i < 1000; i++){ ... // a lot of calculations done here return i; // -> return the value after each loop is done } }
Here it only returns one value, i = 0. Clearly it's wrong.