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;

[Code] .....

View 1 Replies


ADVERTISEMENT

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# :: Use Loop To Load Two Forms Back And Forth Then Stop At Loop 4

Feb 15, 2015

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;

[Code]....

View 3 Replies View Related

C++ ::  Saving PNG File In Console Program / Losing Data?

Jul 18, 2013

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):

ofstream png;
png.open(/*outputfile*/, ios::binary);
FILE* fp = _popen(/*SYSTEMCALL*/, "rb");
string responseString;
if(fp != NULL) {
char a[100];
while(!feof(fp)) {
fgets(a, 100, fp);
responseString += a;
}
}
_pclose(fp);
png << responseString;

Am I missing something or just doing it wrong?

View 11 Replies View Related

C :: Function Not Sending Back Values

Nov 4, 2013

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
}

[code]....

View 2 Replies View Related

C :: How To Loop Back To The Beginning Of Function

Oct 11, 2014

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?

View 4 Replies View Related

C++ :: Will Overflows Loop Back Around And Become Positive Again?

Apr 24, 2012

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?

View 4 Replies View Related

C :: How To Make Function Which Gives Back Two Numerical Values

Nov 3, 2014

How make function which gives back two numerical values. I think needs using structure. now i try found my c book.

View 3 Replies View Related

C++ :: Guessing Game - How To Successfully Loop Back To The Beginning

Feb 5, 2015

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;

int game(){
string playerName;
int guess;

[Code] ....

View 1 Replies View Related

C/C++ :: Shifting Characters - How To Make Letters Loop Back To The Start

Feb 9, 2015

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.

View 2 Replies View Related

C++ :: Change Making Program Prints Correct Values But Prints Them In Loop

Jan 27, 2015

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

3 quarters
2 dimes
0 nickles
3 pennies
but instead it prints
3 quarters
2 dimes
0 nickels
3 pennies
0 quarters
2 dimes
0 nickels
3 pennies
0 quarters
2 dimes
0 nickels
3 pennies

Why it's doing this?

Code:
#include <iostream>
using namespace std;
int coinscount(int& amount, int value) {
int tracker = 0;
int amountdimes = amount;

[Code].....

View 3 Replies View Related

C/C++ :: Array With Two Variables And Loop

Feb 18, 2014

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?

View 7 Replies View Related

Visual C++ :: Find All Variables And Their Values

Oct 13, 2014

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:
//connect to WMI
std::wstring wmiClass = L"Win32_OperatingSystem";
CComPtr< IWbemLocator > pLocator;
HRESULT hResult = pLocator.CoCreateInstance( CLSID_WbemAdministrativeLocator, nullptr, CLSCTX_INPROC_SERVER );
if ( SUCCEEDED( hResult ) )

[Code] ....

View 12 Replies View Related

C :: Cannot Get Out Of Loop - Stuck With Updating Variables

Jul 18, 2013

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

4.00 2.500
4.00 2.050
4.00 2.001
4.00 2.000
4.00 2.000
4.00 2.000
4.00 2.000
4.00 2.000
4.00 2.000

And it continues forever until i manually break the program even though the answer was found, in this example, on the 4th loop.

View 8 Replies View Related

C# :: Losing Image When Using Asp Popup Window

Jun 23, 2014

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();

[Code].....

View 5 Replies View Related

C :: Finding Minimum Values Of Two Decision Variables?

Sep 17, 2014

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;

[Code]....

View 7 Replies View Related

C++ :: State The Values Of Each Int Variables After Calculation Is Performed

May 2, 2013

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.

a) product *= x++;

b) quotient /= ++x;

What is the answer for a and b?

View 4 Replies View Related

C++ :: Variables Declared - How Many Times Loop Executes

Jan 27, 2015

Assume all variable are declared correctly, the following for loop executes how many times?

for (i = 0; i <= 20; i++)
cout << I;

I think 20 but am not sure.

View 7 Replies View Related

Visual C++ :: Re-input Variables After Loop Ended

Oct 18, 2014

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 };

[Code].....

View 2 Replies View Related

C :: Losing Number In Quick Sort Algorithm

May 16, 2013

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;

[Code] .....

View 2 Replies View Related

C :: Losing Contents Of A String Between File I/O Operations

Oct 24, 2013

Here's the code I'm writing:

Code:
#include <stdio.h>
#include <stdlib.h>
char* getTeamCode(char* team);

[Code]....

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.

View 3 Replies View Related

C :: Passing Int And Float Variables From Main And Getting Values From Another Function

Feb 3, 2015

I have the main() - which has entries like

Code:

main() {
int ss, ret, z;
float yy;
ret = function1(&yy, &ss, &z);
//int function1(flat *cc, int *dd, int *k) - is it correct?

[Code]...

View 5 Replies View Related

C :: Read From And Store Values Of Each Line In Multiple Variables

May 6, 2013

So I have this text file that I am trying to read from and store the values of each line in multiple variables. Let's say my text file contains

AXSYZ3482 Tom 100 112 and my code below here works fine when the lines in the text file is separated by spaces.

Code:

while (fscanf(fp, "%s %s %d %d
", userID, name, &startLoc, &endLoc) != EOF) {
printf("%s %s %d %d
", userID, name, startLoc, endLoc);
}

But let's say my file was to look like this instead.

AXSYZ3482:Tom:100:112

But if i try this below...

Code:

while (fscanf(fp, "%s:%s:%d:%d
", userID, name, &startLoc, &endLoc) != EOF) {
printf("%s %s %d %d
", userID, name, startLoc, endLoc);
}

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.

View 4 Replies View Related

C++ :: Class Syntax - Variables Are Initialized With Values Between Parentheses?

Mar 1, 2013

Here's a bit of code:

CvClimateInfo::CvClimateInfo() :
m_iDesertPercentChange(0),
m_iJungleLatitude(0),
m_iHillRange(0),
m_iPeakPercent(0),

[Code] ....

does this means that these variables are initialized with the values between parentheses?

View 2 Replies View Related

C++ ::  Vertical Histogram - Variables In For Loop To Print Stars

Dec 6, 2013

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

[Code] .....

View 4 Replies View Related

C++ :: Output All Prime Numbers Between Values Of StartNum And EndNum Variables

Apr 7, 2013

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.

void PrimeFinder::run(){
bool isPrime = false;
for(int i = startNum; i <= endNum; i++) {
for(int j = 2; j < i; j++){
if((i % j) == 0)

[Code] ....

View 6 Replies View Related







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