C :: Got Stuck In Simple Coding Process / How To Initialize Any Value

Mar 2, 2013

in order to calculate some logarithm approximation I need to make a variable, say s, search through the whole integer numbers.

Code:
int s;
for {;;s++){
}

[Code] ....

since the variable needs to be initialized right? how to go through all the numbers?

View 3 Replies


ADVERTISEMENT

C++ :: Enter Value For Coding

Oct 1, 2013

some where in main:

char value;
char* sname;
sname= new char[20];
for(int i=0;i!=19;i++)
{
cin>>value;
sname[i]=value;
}

I need a stopping case when user press enter array get closed and add '' at the end but how to do that?

View 1 Replies View Related

C++ :: Coding And Debug Time Per LOC

Mar 23, 2013

I just spent 3 hours writing and debugging 37 lines of code. Is this normal or am I "below average" in coding abilities. I come from a C background and decided to write C++ code that I finally got right as shown below for the specific example:

Code: #include <iostream>
#include <fstream>
#include <string>
#define SPACE_SEARCH 10
using namespace std;

[code].....

I think it was more the learning along the way that consumed atleast 75% of my time for this specific case. But then again, I read that programming always entails learning along the way and so its somehow no excuse for the long time taken in this specific case.

So as a matter of interest, what pace do all of you operate on, on average? i.e. LOC/day, Debugs per day or any other indicator of productivity?

View 3 Replies View Related

C :: Coding MP3 File Into A Program

Oct 16, 2013

Is there a way to put a mp3 file into a c program without having the windows media player pop up in the background each time you compile the program? I just wanted to input a few seconds of an audio file..

View 3 Replies View Related

C++ :: How To Start Coding Audio Synthesizers

Mar 20, 2013

I'm interested in learning how to write the software for audio synthesizers. a friend of mine started on the hardware side for them and, as i have no experience with this type of code.

View 7 Replies View Related

C++ :: Compound Interest Formula Coding

Sep 24, 2014

Im having problems coding this
A = P(1 + r/n)nt

//Declared test cases
float principal = 200000.00, annualInt = 0.03;
float years = 10.0;

float calcInterest1(float principal, float years, float annualInt) {
float interest1;
float nt = annualInt*12;
float A = principal+annualInt;//Accrued Amount
interest1 = (A = (principal*(1+years/100))pow(nt));// A = P(1 + r/n)nt
return interest1;
}

View 1 Replies View Related

C++ :: Check The Coding Style Use In A Program?

Apr 30, 2014

Is there any opensource tool which can check the coding style use in a program.

View 2 Replies View Related

C/C++ :: Falling Object Error When Coding

Mar 4, 2014

Write a program that computes how many feet an object falls in 1 second, 2 seconds, etc., up to 12 seconds.

1.Have a procedure called FallingDistance which has one input parameter, seconds, and one output parameter, distance.
2. Compute the distance in feet an object falls using this formula: d = ½ gt2
(where g = 32.2)
3. The main program should call FallingDistance within a loop which passes the values 1 through 12 as arguments.
4. Print a table with seconds and falling distance in feet.

Sample Output (This program has no input)

Seconds Distance
================
1 16.1000
2 64.4000
3 144.9000
4 257.6000
5 402.5000
6 579.6000
7 788.9000
8 1030.4000
9 1304.1000
10 1610
11 1948.1000
12 2318.4000

In C++, the procedure is called a function. Instead of using an output parameter, your C++ function FallingDistance should return a result of type double. This is what I created:

#include <iostream>
#include <cmath>
#include <string>
using namespace std;
const double g =32.2;
double fallingDistance(double);

[Code] ....

which gave me this error:

1>------ Build started: Project: Lab 6, Configuration: Debug Win32 ------
1> Source.cpp
1>c:usershanahdocumentsschoolprogamming ilab 6lab 6source.cpp(27): error C2065: 'fallingdistance' : undeclared identifier
1>c:usershanahdocumentsschoolprogamming ilab 6lab 6source.cpp(36): error C2065: 't' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

View 4 Replies View Related

C++ :: How To Open Notepad Application Through Coding

Aug 14, 2012

I java We can be able to open any application through coding.. likewise Is it possible to open through c++?

View 3 Replies View Related

C++ :: Coding A Loop Inside A Class To Use In Main

Feb 22, 2013

I am writing a program where all work is done in the class methods. Main is used to call the methods. I need to know how to get a loop to work without any variables in main that can be used outside the methods. This is what I have in main:

#include <iostream>
#include <string>
using namespace std;
#include "FerryBoat.h"
int main() {
//create a constructor for a ferry boat
FerryBoat myBoat('B', 20, 'A');

[Code] ....

View 3 Replies View Related

C Sharp :: Coding For Quantities In Online Shopping Carts?

Jan 11, 2013

I am trying to create an on-line product store. I'm having trouble with setting up the code to correctly acknowledge quantity desired per product item in the shopping cart at check-out. I want to be able to capture multiple impressions/hits/clicks per item and increase the # in the quantity box each time someone clicks on the same item. For example, if product A is clicked 3 times, then the quantity in the shopping cart should show "3". If it's clicked 5 times, it should show "5" and so on ... However, right now, it's showing the product multiple times in the shopping cart with a quantity of "1" for each time the item was clicked. How can I correct this?

View 2 Replies View Related

C :: Why GDB Getting Stuck

Mar 2, 2015

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

[code]....

View 6 Replies View Related

C++ :: Stuck With A Do While Loop

Mar 27, 2013

Alright I have a program that needs to calculate different rates of commission for a particular sale

I'm stuck in a loop and I'm not sure how to update the final cout statements as well.

#include <iostream>
#include <cmath>
using namespace std;

[Code].....

and yes those are the actual rates i need to calculate and they are in increments of 5%

View 2 Replies View Related

C/C++ :: Stuck In A Loop And Can't Get Out

Feb 15, 2015

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

[Code].....

View 2 Replies View Related

C++ :: Stuck In Infinite Loop?

Feb 24, 2015

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...

View 1 Replies View Related

C++ :: Values Getting Stuck In Memory?

Apr 4, 2013

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

[code]....

View 10 Replies View Related

C++ :: Variable Stuck In A Loop?

Feb 7, 2015

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

[code]....

View 2 Replies View Related

C/C++ :: Stuck On Using Pointers With Malloc

Apr 18, 2015

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

View 3 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 Sharp :: Stuck In Infinite Loop?

Sep 9, 2012

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

[Code].....

View 2 Replies View Related

C++ :: Randomly Generating Probabilities - Function Stuck

Oct 29, 2014

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?

View 3 Replies View Related

C++ :: Stuck On Getting Highest Number Output Using Array

Feb 25, 2014

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;

[Code].....

View 4 Replies View Related

C++ :: Stuck On Student Project / Classes And Objects

Aug 28, 2014

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.

View 2 Replies View Related

C :: When Try To Iterate Two Times Or More - Program Gets Stuck In Infinite Loop

Mar 18, 2014

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.

testData8.dat:

Code:
12 9
13 756

View 3 Replies View Related

C++ :: Math Game Program - Stuck On Input File

Oct 21, 2013

I am making a math game program that simple and need to have a user input a name and then that name.txt is brought up and use variables from the text to add to their score. heres my code kinda long.

#include <iostream>
#include <cmath>
#include <cctype>
#include <string>
#include <ctime>
#include <cstdlib>

[Code] ....

View 10 Replies View Related

Visual C++ :: Data Stuck When Debugging With Serial Port

May 10, 2014

I am making a MFC application with VC++2012 with receiving data from Serial Port and the data is stored in a Listbox, then after processing (convert into numbers) and get these data to draw a sine wave on the chart. (I intend to make a virtual oscilloscope).

Everything works ok at the beginning, but after receiving about 300 items or above (in the Listbox) the value seem stucking (or lagging) and work very slowly.

I receive data by the SerialPort_DataReceived() method, and process of converting and drawing chart also in this method, I think this makes the system overload!!

View 1 Replies View Related







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