C/C++ :: Loop Indentation - Output With No Extra Whitespaces
Mar 1, 2015
So I'm having trouble with my code. Got it to work, but having issues in terms of indenting my increment. For this example, I will use * as whitespaces.
Expected output:
0
*1
**2
***3
Your output:
0
*1
**2
***3
*****
The expected output has no extra whitespaces, but mine does. What am I doing wrong?
#include <iostream>
using namespace std;
int main() {
int userNum = 0;
int i = 0;
int j = 0;
for(i =0; i <= userNum; i++){
As I was testing it, the program suddenly stopped giving an output. Here is the code:
#include <iostream> using namespace std;
int main() { cout << "Ten people ate breakfast with you this morning. Each of them " << "had pancakes. Please enter how many pancakes each of the ten people " << "ate. " << endl;
[Code] ...
The while loop after int glutton does not work and seems to stop the program. I replaced the "glutton" in the cout with "testing testing" and it still did not work. However, when I commented out the loop, it appeared. Finally, it can't be what's inside the loop, because I commented that out too, and it still didn't work.
so i got this piece of code today having some slight errors with it, how its actually done as i want to know where i have gone wrong here is the code .. Using a for loop to input and output array values
*/ #include <stdio.h> int main(void) { /* Declare an array of integers */ int Grades[5]; int nCount; /* Populate the array */ for(nCount = 0; nCount < 5; nCount++)
[URL] when I try to write my output to a file. I am building a life insurance premium calculator with c++. What my calculator does is read in a text file called "policies.txt" containing a number of different policies. For example:
Pol1 M N 20 100000 1 .04 99 Pol2 F S 30 100000 1 .05 99 Pol3 M S 72 750000 1 .03 99 Pol4 F N 45 1000000 1 .05 99
And using this, it creates a single premium. Once the calculator calculates the premium of each policy, I want it to write out the premium amount of each policy to a textfile called "output.txt". The problem is that when I check my "output.txt" file, only the premium for the last policy shows up. It only reads:
Premium for Pol4 is 220384 When I want it to read:
Premium for Pol1 is 14101.6 Premium for Pol2 is 14221.2 Premium for Pol3 is 582391 Premium for Pol4 is 220384
How come only the last policy is showing up? and is there any way to make all four policies appear in my output text file? Here is my code:
How to fix this when i run the program and enter my name then output my name in vertical position using the for loop and press enter the program do not stop
My loop is outputting data incorrectly. I have inbound web data that come in sets of 7. I am trying to in insert the 7 records into a vector and then display the vector content followed by a new line.
Basically I'm supposed to use a while loop to generate a random number and use a switch statement to output the appropriate information. I feel like I'm missing a few things that are very simple.
The errors are: warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data warning C4700: uninitialized local variable 'randomNumber' used
I have this code that im stuck on what i need to do is Extend the code such that when it starts the user is asked to input values to specify each of the three ranges before moving on to accept and tally the main values how do i do that Using a for loop to input and output array values Also calculate the average
*/ #include <stdio.h> int main(void) { /* Declare an array of integers */ int Grades[5]; int nCount; int nTotal = 0; /* Declare and initialise the value */ float fAverage;
I need to write a program to input 6 temperatures in degrees Fahrenheit and output it in degrees Celsius. I used a for loop but it keeps giving me 0 as the output whenever I enter a temperature...
Code:
#include <stdio.h> #include <math.h> int main() { double farenheit,celsius; for(int i=0; i<6; i++) { printf("Enter temperature in degrees farenheit: "); scanf("%lf",&farenheit); celsius = (5/9)*(farenheit-32); printf("Temperature in degrees celsius: %lf ",celsius); } }
I pretty much got the assignment done. All it asked for was that you make a C program that displays which manufacturer owned a disk drive based on the code entered. Pretty simple. Just enter 1, 2, 3, or 4 and get the associated manufacturer. Though I am trying to implement an error messege to it for any interger that isn't 1-4.
Code: #include <stdio.h> int main() {
[Code]...
o errors are given and it works fine as long as you enter 1-4, but when you enter any other didgit it just stops the program without any messeges.
While running it gives the runtime error: "Extra parameter in call to factorial."
#include<iostream.h> #include<conio.h> int factorial(long int); void main() { clrscr(); long int a; cout<<"This program displays the factorial of the number you enter."<<endl;
I got this code from a wiki that taught me how to make C code that plays audio, and with a few changes I was able to get it to take a command-line argument as the music file name. Here it is
The only problem is, even though I guess it needs to create a window to work with SDL, is there any way you could hide it or something so the user can't see it? I don't really want to see it ( I'm planning on running it from Batch files or C applications as an easy way to play an audio file once ), because if I did, I might as well just use a default audio player instead.
I am new to c++ and have started creating a dummy program to perform a simple task of writing a few strings to the console, which are first generated using random generation. When I execute the code, an extra line for each generated object appears in the console.
int gemNum; cout << "This program calculates the value and type of gems "; cout << "Please enter the number of gems: "; cin >> gemNum; vector<int> gemVector(gemNum); vector<int> gemCollection = fillGemCollection(gemNum); vector<int> gemSort = sortGems(gemCollection); vector<string> gemResult = finalGemValue(gemNum, gemSort); for(int i = 0; i<gemResult.size();i++){ string gemString = gemResult[i]; cout << gemString << endl; }
This program calculates the value and type of gems..Please enter the number of gems: 4
10 hematite 40 carnelian 60 onyx 120 silver pearl Press "e" and enter to end program
I have a class and I would like to be able to pass an extra parameter to the function that is executed.
BigInt operator / (BigInt N,BigInt D) { ... }
is what I have now. but I would like to do something like this. so the default value for a is 10. and if the user does something like N/D (12) Then the value of a is 12.
The program works, other than if I place the cursor below the last line in my merch file, the program outputs a line of garbage. The only solution I could find is to leave the cursor on the last line.
I am trying to add some functionality to this project: [URL] ...
Under this [URL] ...
This latest comment based on;
host.data = (u_char *) "112.168.231.19:80"; for (i = 0; i < peer->name.len; i++) { peer->name.data[i] = host.data[i]; } or more simpler: peer->name.data = host.data;
States: "Because strings always require an extra memory buffer (and the burden of memory management) while primitive values like booleans and numbers don't."
Which makes sense since a boolean change (down/up) does actually changes a runtime value, however the string replacement shows via '/upstreams' that the value has changed but at runtime it is still using the old value.
So in short it looks like I do need a buffer to change the string value.
My question is why? if 'peer->down' works on a memory fragment where its value resides then why doesn't a 'peer->name.data = host.data' do the same thing? can this be done without a buffer? once you allocate memory and store host.data in to this where do I copy it to?