C++ :: Loop Program To Go Back Without Losing Values Of Variables?
Mar 30, 2014
I know that returning to main() is not a good idea but how will I loop the program to go back to the position selection when the voter is done voting for the last position.
when I run the program it seems fine. getting the votes from President to PRO Position is fine. The problem is how will the next voter vote without losing the vote (tally) of the previous voter?
FLOW:
SELECT POSITION (a-e) ---> SELECT A CANDIDATE (a-c) ---> (this goes on until the position of PRO) ---> ( then go back to the POSITION SELECTION)
After every vote there is a case statement for which I can choose to vote for the next position, quit, or show results (and after showing the results it will go to the next position to vote)....
#include<iostream>
#include<string>
#include <conio.h>
using namespace std;
int pca=0,pcb=0,pcc=0,ptv=0;
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;
I am working on a project that uses a web service to extract a PNG image from a web server and save it on a local machine. It's done via a system call. I can get the output of the system call to a FILE but it appears to be losing data, most notably the PNG chunk names (IHDR/PLTE/IDAT/IEND, notably). (Unfortunately piping the output to an exterior file does not work through a system call.) The end result is ~6KB smaller than the file I am intending to retrieve.
This is the code I'm using (adapted from other material I found via searches here):
I am trying to get all these functions work together and send the value of countX and countY back into main from function2() and function3() to be used by function4() later on.. But I keep getting 0 printed out and I am not quite sure why.
Code:
#include<stdio.h> #include<stdlib.h> #include<time.h> #define maxrow 20 //defines maxrow as a constant of 20 #define maxcol 30 //defines maxcol as a constant of 30 }
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?
If I have a positive double and cast it to an int. If it overflows, I know that most of the time, the value of the int becomes negative. If it overflows far enough, will it eventually become positive again?
Code: double d = 34192384732194872394837249832743984738.; int i = (int)d; std::cout << i << std::endl;
Is there any value of d > INT_MAX that will cause i to be positive?
So I'm making my first program w/ C++ and its a game guessing game. I've learned how to use booleans, chars, strings, if/else, loops, and input. Anything past that I dont know. I've gotten my game to work properly except for the fact that when you guess incorrectly, the program closes. I want the program to go to the beginning of the program again so the user can restart. So far i've gotten the loop to beginning thing to work but not well. It'll only repeat twice before closing again and it'll say the user got the wrong answer even if it was correct. Here's my code
#include <iostream> #include <string> #include <random> #include<ctime> using namespace std;
I have to make a function that i'll later be able to use for a ceasar cypher. The letters should shift a user inputted number. This is what I have so far:
char shiftChar(char c, int s) { char ch = c; int shift = s; int newC; newC = int(ch) + shift; return newC; }
The problem with this, is that it doesn't loop back to the start of the alphabet once i get past z.
I have a program that makes change from an amount. It works fine, but the output is the correct output looped over and over. I have tried everything, but it still doesn't work. For example, a amount of 98 should print
I have two variables t and x in an array that alternate. I want to add two t's and find the average and then do the same for the x's. After that, I want to find the slope of x -> t. My problem is that I specify the n for t, but since it's local I can;t use it for the slope. Here's my code so far:
#include <iostream> using namespace std; int main() { double PA [8] = {0.0001234, 1.0005434, 0.0005678, 1.0023423, 0.00063452, 1.0001546, 0.00074321, 1.00017654};
[Code] ....
And, can I actually use the n2 as an index, or will the processor not understand that?
In the following code I want to iterate through "Win32_OperatingSystem" to find all variables and their values. Using GetNames() I can get the names of all the variables but the subsequent Get() call fails to return a value.
Code: #include<stdlib.h>#include<stdio.h> #include<unistd.h> #include<math.h> int main(void) { double N, NG, LG, epsilon, root; // setting all variables to type double
[Code] .....
The goal is to create a program to calculate the square root of a number provided by the user to an error tolerance 0.005
Looking around i fond the Code: fabs(NG - LG) < epsilon); section that was very similar to what i was using, but if this is better im down for that.
My issue, from what i can see, is the updating of the values of LG. if the test for error tolerance fails then LG needs to take on the value of the results of NG.
Now I am not 100% that is the point of failure due to the fact the script does calculate the root properly, but it never exits the program once it reaches the tolerance level.
Code: imac:ENG-3211 user$ ./hw_4_1
Please enter the number you wish to find the square root: 4
I am creating a website in which a user can upload an image to a sql database. It is converted to varbinary and then read into an Image object using a http handler to convert it to an image. this all works fine. When I open an popup window I am reading data from specific rows into textboxes, thus when the user confirms any changes the rest of the data stays the same. How can I hold the Image and redisplay it when returning to the main page after closing the pop up. It currently sets the image in the database to null as the file upload object has not been given a directory location all the time. This is my attempt at reading the image from the database and then reapplying it if the file upload is empty
private void ChangeFilm(int id) { SqlConnection con = new SqlConnection(my settings go here); con.Open();
I am trying to solve a MIP problem using C with Cplex linker. I need to find min value of two decision variables, as far as i know, i should write as a constraint because they are decision variables. "if" statement does not work for decision variables. here is some part of my model in C.
Code:
void TSPMIP(int Scenario, int Agency) { int i,j; double tmpDouble;
Question: State the values of each of these int variables after the calculation is performed. Assumed that, when each statement begins executing, all variables have the integer value 5.
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 };
I'm tinkering with a serial quick sort algorithm. Normally I use qsort() but I wanted to test this.
Somehow I loose the highest number. I can't see where I drop it.
Code: // function to quicksort, leave them in front of qsort. void swap(float_t *left, float_t *right){ float_t temp; temp = *left; *left = *right; *right = temp;
Why the placement of the code on line 21 above matters.
It grabs the correct string just fine. If I write a printf just below it, it prints the string it should correctly. However, if I do a printf of the string OSUteamCode below the fopen call on line 23, it prints blank.
So the first thing I did was move it below the fopen line. It worked, finding and outputting the first game in "game.csv" just fine, but not the other 11. Debugging with printf shows that the contents of OSUteamCode again disappear after the fopen call in the addLineCSV function.
I'm not understanding why that happens. The only thing I can figure is there's something going on with the file I/O commands that I just don't understand, but I can't find anything online that explains what that might be.
It seem to store the entire line in userID including the ":". I want to ignore the ":"'s and store everything in between in respective varibles in the order specified above.
So first string in userID, then ignore the :, then second string in name, and ignore the next :, and so forth.
I want to create a vertical histogram in my code. I already made it go vertical but not the way I want it.
Example: I want it like this:
Range1 Range2 Range3 Range4
And asterisks under each one, depending on the user input. (My code is below and doing it on here doesn't make it come out correctly)
But what I've managed to do is this:
Range1 * * *
Range2 * *
Range3 * * * *
Range4 * *
Which I don't want. I want everything else to stay pretty much the same since I can only use some features such as Arrays and really basic functions.
Here is my code: (Worked fine last time I used it and I am doing it on Visual Studio 2010 (at uni) and 2013 (on my laptop)).
#include <iostream> //Start of code using namespace std; int MarkValueInput; //Mark entered by user //Counter variables for ranges in While Loop int counterlow; //Counter for low range int countermidlow; //Counter for mid-low range int countermidhigh; //Counter for mid-high range int counterhigh; //Counter for high range
The code below is suppose to output all the prime numbers between the values of startNum and endNum variables. but its not working correctly instead it display all the numbers between startnum and endNumber including non-prime numbers.