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
I need to write a C++ program, that extracts certain variables, x y z, from a file that is continuously being updated x y z. These variables are going to be used to recalculate a new answer.
My question is to see if it is possible to have an include .h file that is always being updated so that I can extract these three variables from it, and always have the newest venison of each variable, so that the answer to the equation is always the newest updated. Should I use fopen or fwrite to do this.
how to ask for the input (className) without getting stuck in the loop. When I remove
char className; cout << "Enter the class name: " << endl; cin >> className;
it works fine. When I leave it how it's displayed below it goes in an infinite loop. By the way I think "char" is not the appropriate way to declare className. If I want to output it later, should I changed it to "string"?
#include <iostream> using namespace std; int main() {
my code seems to enter an infinite loop should a user mistakenly enter a character other than a digit. The code is about selecting from a preset number of options, numbered 1- 4. If the user mistakenly enters a letter for example, instead of a number, the infinite loop kicks in...
I want to create a loop that that generates a random number set and gives the user the option to run the loop again for a new number. I have that working but when the loop ends the variable value does not leave the loop. I tried a posttest and pretest loop.
Is it possible to declare/create/alter a variable in a loop and have that value exit the loop to use in the code later? I am still learning about global variables.
#include <iostream> #include <cstdlib> #include <ctime> #include <string> int oneDiceSix() // Roll 1d6 {int oneDiceSix = 1+(rand()%6); return oneDiceSix;} //end function
I currently have a hangman game in the making. Which is giving me debugging issues when I go to pick a letter, it will keep asking for a letter, if I place a break; within the loop it asks for a letter and says you've won. I know all I should need is a couple extra lines somewhere within the code.
/// Play game public static string playGame() { Words words = new Words();
So I am working on making a game. The first thing I did was make a window class. This correctly makes the window and displays it.
Now, I run my game loop and it just freezes the window and shows the Application has stopped working message box. I believe this is because the Window is not actually being updated.
My game loop however, looks like this.
bool run = true; while(run) { Window::Render(); if (Window::IsCloseRequested())
I'm having trouble getting my loop to work correctly. If I iterate the for loop once it works as expected and displays proper output. When I try to iterate two times or more the program gets stuck in an infinite loop.
I am trying to get this code eventually to read in a maze file to move the smiley face around in. But right now my current snag is the yes or no to enter the for loop.
#include <iostream> #include <windows.h> #include <conio.h> #include <time.h> using namespace std; int main() { int name; char ans;
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?
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 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
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;
so my program is quite simple and it works fine when i execute it but when i try to run through it with gdb i get an error. so this is what i get from gdb
Code:
Breakpoint 1, main () at fun.c:4 4 { (gdb) watch a Hardware watchpoint 2: a (gdb) next 6 a=0;b=0;c=0; (gdb) next
I have a school project where I have to create a class with 2 attributes that default to 1. To verify that they are at 1, I have a cout before any user inputs or value manipulation. It works for the most part. What happens is that if I change the defaults to 17, the cout will retain the old values until I have an unsuccessful build (remove a semicolon from the end of the line). When I have a successful build (put that semicolon back), the cout displays the changed values. Change the values back to 1 and the same thing happens again until I have an unsuccessful build then a successful build. Are the old values getting stuck in memory somewhere?
// Rectangle.h // Chapter 9_Problem 9.11_Page 412 #include <iostream> using namespace std; #ifndef RECTANGLE_H #define RECTANGLE_H class Rectangle // Rectangle class { public: Rectangle(double = 17, double = 17); // default constructor setting values to 1
So this is my first attempt at actually writing code, I have a little basic core functionality set up and I'm 99% sure I'm doing something very fundamentally wrong with pointers.
#include <stdio.h> #include <assert.h> #include <stdlib.h> #include <string.h> struct Creature { int pow; int tou;
[code] ....
Error generated:
magic.c: In function "main": magic.c:71:26: warning: initialization from incompatible pointer type [enabled by default] struct Creaturedb *db = Initialize_creaturedb; ^ magic.c:72:22: warning: initialization from incompatible pointer type [enabled by default] struct Player *pl = Initialize_player; ^
I am currently just trying to update a record in a SQL database.I can add a record and delete a record just fine but when I go to update I get no errors but it just doesn't update.
Here is what I have and done coding for hours trial and error
private void btnAddProd_Click(object sender, RoutedEventArgs e) {//validate method // product = new Product(txtProductName.Text, Convert.ToDecimal(txtProductCost.Text), txtProductType.Text); product = new Product(); MakeProduct(product); if(modify) { Product theOneAndOnly = new Product();
I want to search for the "movie_code" and change the [movie_status] from Active to Inactive.
So lets say for example i have a movie code 12345 saved in my movie file. I want to change the value from "Active" to "Inactive"for argument sake.
This is the code i was trying to do it with:
FILE *movie_fp; movie_fp = fopen("movie.dat", "r+b"); int m_code; MOVIE movie_data; printf("*** Welcome to the movie updater! *** "); if(movie_fp != NULL){
I've just integrated the Windows SDK V7.0A into my VS2005 application, and I'm getting the dreaded "Application configuration error" when I try to run it on an XP machine.
It runs fine on the development machine, and some customer machines (Win7 and Win8), but will not run on XP due to missing/incorrect version dlls.
I've rebuilt all my libraries, but still no joy.
So, my first question is - If I upgrade the Windows SDK to V7.0A, do I also need to use MFC 10 and msvcrt10, or can I stick with MFC 8?
The next question is, how do I find out which dlls are missing, and which libraries or other dlls are requesting the missing versions?
I've written some code to randomly generate probabilities:
int Queue::car_per_hr() { srand( time( NULL )); int prob = rand() % + 101; // Probability in percentage from 0 to 100 int cars; //no of cars per hr
[Code] ....
So it checks through the range of possibilities: 0-20%, 21-40% etc. I then have this to implement it:
#include <iostream> #include <ctime> #include "queue.h" using namespace std; int main(){ Queue car_wash; int NO_HOURS;
[Code] .....
For some reason though, everytime I call the car_per_hr() function, the probability just stays the same. It's output is always locked to the same thing it had to begin with?
Here is my code and everything works except i can not get the highest array number to be output. it always says 10.
My instructions are:
(1) Create a 10-integer array called data (2) Set a pointer ptr to point to array data (3) Output the elements in array data using pointer ptr (4) Find the largest element in the array data using pointer ptr
#include <iostream> #include <cstdlib> using namespace std;
Working on a project for a c++ class and got a bit stuck.
What I am trying to do is include a class for calculating home square footage in a program I have written for my last project. When I do this, I get errors in codeblocks, on lines 74 and 87, "expected ; before 'box', and 'box' was not declared, respectively. Unsure what my snafu is... I had these two programs separate and both run without errors until I combine the two into one program.
I am writing a program that manages a group of tool bins. This group is handled as an object that is an array of two element structures called InvBin. I initialize the bins with data from a file which contains the descriptions and initial quantities. I also have functions to add or subtract items from a bin and a function to display a report of the description and quantity of all of the bins.
The add and remove functions work correctly based on the cout statement in the functions, however when I display the report, it displays the initial quantity instead of the new quantity. In addition, when I use the add and remove functions again on the same bin, they use the initial quantity.
These are the add and remove functions and the report function from the main program.
Code: //Adds an item to a bin void addItem(HANDLE screen, BinManager tools, int &count) { int binNum; int addNum; system("cls");