C :: Possible To Output By Using Only One Loop

Jul 21, 2013

is it possible to output like this using only one loop? if yes, how?

target output Code: ABCDE

EDCBA here is my code but using one loop im not getting my target output Code: #include <stdio.h>

main()
{
int x, y;

for(x='a', y='e'; x<='e'; x++, y--)
{
printf("%c
%c", x, y);
}
getch();
}

View 6 Replies


ADVERTISEMENT

C++ :: While Loop Stops Output

Jun 19, 2014

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.

View 2 Replies View Related

C++ :: Struct Output Using A Loop?

Nov 6, 2013

trying to output my struct to a for loop. I understand how to output the struct but not into a for loop.

#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
struct Date {
int day;
int month;
int year;

[code]....

View 16 Replies View Related

C/C++ :: For Loop Not Producing Correct Output

Nov 14, 2014

Something is wrong with option 1. For some reason it adds 1, 2, 3, 4 ... 5 onto the output and I can't think why. Here is a screenshot.

Also how can I make the output a little neater? I tried to use but it just looks horrible.

I had linked the source code! Why is there no edit button?!

#include<iostream>
using namespace std;
int main(){
int option;
cout << "Welcome to my program. Please select a following option.

[Code] .....

View 3 Replies View Related

C++ :: Using For Loop To Input And Output Array Values

Jan 23, 2014

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

[Code]...

View 3 Replies View Related

C++ :: Count Function - Nested Loop Output

Feb 28, 2013

What does the following nested loop output ?

count = 1;
while (count <= 11) {
innerCount = 1
while innerCount <= (12 - count) / 2) {
cout << " ";
innerCount++;
} innerCount = 1;
while (innerCount <= count) {
cout << "@";
innerCount++;
} cout << endl;
count++;
}

View 9 Replies View Related

C++ :: Writing Output Of While Loop To Text File?

Jul 30, 2014

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

double ratesmn[86] = {
#include "MaleNonSmoker.txt"
- 1
};

[Code]....

View 2 Replies View Related

C++ :: Displaying Correct Output By Using For Loop (with Pointers)

Feb 4, 2014

I wanted to display the correct output by using a for loop at the end of my code, but for some reason it's not working correctly.

#include <iostream>
using namespace std;
int main() {
int* ipArray[3];
for(int i = 0; i < 3; i++) {
ipArray[i] = new int [5];

[Code] .....

What I wanted to do is pretty much match my 1st out put like 0 1 2 3 4 but my 2nd output only outputs 24's and I don't know why

View 11 Replies View Related

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

[Code] ....

View 5 Replies View Related

C++ :: Enter Name Then Output Name In Vertical Position Using For Loop

Feb 21, 2013

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

#include<stdio.h>
#include<conio.h>
#include<dos.h>
main() {
char name,n;
clrscr();
printf("Enter Your Name:");
scanf("%c",&name);

[Code] ....

View 3 Replies View Related

C++ :: Incorrect Vector Output Loop Error

Nov 21, 2014

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.

Code:
char buff[BUFSIZ];
FILE *fp = stdout;
char * cstr = buff;
vector<std::string> vrecords;
while(std::fgets(buff, sizeof buff, fp) != NULL){
for(int i = 0; i < 6; ++i){

[Code] ....

expected output:

Found buy!
198397652
2014-11-14 15:10:10
Buy
0.00517290
0.00100000
0.00100000
0.00000517

[Code] ....

View 14 Replies View Related

C++ :: Partition Quicksort Algorithm - Output Is In Infinite Loop

Aug 31, 2013

I am trying to code a partition quicksort but the problem here is at the output is in an infinite loop:

The input : 4 3 5 7 2

The expected output : 2 3 4 5 7

But my output is infinite :

2 3 4 5 7
2 3 4 5 7
2 3 4 5 7
.
.
and so on

[Code:
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
/* Head ends here */
void partition(vector <int> ar) {

[Code] .....

View 5 Replies View Related

C++ :: Using Rand Function In While Loop And Output Using Switch Statement

Jun 12, 2014

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

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

using namespace std;
int main(){
int i = 0;
unsigned int randomNumber;

[Code] .....

View 2 Replies View Related

C++ :: Using A For Loop To Input And Output Array Values Also Calculate The Average

Jan 24, 2014

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;

[Code]...

View 1 Replies View Related

C/C++ :: Input 6 Temperatures In Degrees Fahrenheit And Output In Degrees Celsius - For Loop?

Mar 9, 2015

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

View 5 Replies View Related

C :: Loop Does Not Work And Program Quits Without Displaying For Loop Function

Oct 13, 2014

We are making a program--but every time we input a value for scanf, the following for loop does not work and the program quits without displaying the for loop's function. We are not getting any errors.

View 11 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 :: Extra Loop Being Executed In Do-while Loop

Jul 1, 2013

Code:
#include <stdio.h>
#include<ctype.h>
void try5t(){

char choice;
int choiceint;

[Code] .....

Loop is repeated an additional time as shown in the screenshot:

View 9 Replies View Related

C++ :: How Much Milliseconds To Loop Through For Loop

Feb 20, 2014

Given a for loop:

int i;
for(i = 0; i < 1000; i++)
;

How many nanoseconds, or microseconds or milliseconds does it take for each iteration? And why do some use it as a timer mechanism?

View 3 Replies View Related

C/C++ :: How To Change For Loop Into Do While Loop

Apr 19, 2014

I already made a nested for loop into a while loop (below this) and now I'm trying to make the outer for loop into a do while loop, but it's not working.

#include <iostream>
using namespace std;
int main () {
int len;
int j;
int i;

[Code]....

And I can't make this code do the same thing. It stops after one loop, instead of continuing to the end. Why won't the loops continue?

#include <iostream>
using namespace std;
int main(){
int len;
cout << "Enter a number: ";

[Code] ....

View 2 Replies View Related

C/C++ :: Convert A While Loop To A For Loop?

Mar 25, 2012

I need to convert the following while loop:

count = 1;
while (caloriesForItem != 0, count != numberOfItems )
{
cout<<"Enter the calories: ";
cin >> caloriesForItem;
totalCalories += caloriesForItem;
count++;
}

This is what I have come up with:

totalCalories += caloriesForItem;
for (count = 1; caloriesForItem != 0; count != numberOfItems)
{
cout<<"Enter the calories: ";
cin >> caloriesForItem;
count++;
cout << "Total calories eaten today = " << totalCalories << endl;
}

However the output is not the same?

View 6 Replies View Related

C :: How To Get Output Of Program

Dec 8, 2013

how to get the output of this program.. I'm not completely lost but I need it in the simplest terms.

Code:

/*Recursive Trace
Written by Ron
April 2006
*/

[Code]....

View 9 Replies View Related

C++ :: Output Array To CSV?

Sep 21, 2014

So I have an array portfolio [i][j] where i and j are determined by inputs by the user. I can get the code to fill the array with the correct values; however, I can not figure out how to output the array to csv.

Is there a simple way to output to a csv? Is it easier to create the csv file and just write to it?

This is all I have so far:

for( i=0; i<sizevol; i++){
for(j=0; j<sizespot; j++){
myfile.open ('')
}
}

View 1 Replies View Related

C++ :: How To Use One Function Output In Another

Mar 17, 2013

In my code the cout phrase is supposed to give me an angle in degrees. no matter which 2 points i enter in, it always outputs the angle between them to be 57. This is because the acos value of 0 in degrees is 57. The program compiles without error.

Here is the code:

/*
Synopsis: This program reads in the coordinates of two 2D vectors and outputs the angle between the vectors in degrees.
*/

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
// function prototypes
// ENTER FUNCTION PROTOTYPE FOR normalize() HERE.
void normalize(double & x, double & y);

[Code] .....

View 2 Replies View Related

C++ :: How To Output From TXT File

Aug 20, 2014

So I have a .txt file with, Name >> Username >> password >> adminstatus. It is filled with various names. for e.g.

Bob bobby bob123 1
tim timmy tim123 1
rit ritty rit123 0
john johnny john123 0
mary maryy mary123 mary 1

1 will represent admin in the program and 0 will represent a normal user. I want to make part of the program do something like this. > If adminstatus = 1, discount rate =3%. The thing is I will be using UDF to do so and I am unsure of how I am going to read for each user. What I mean by this is. If tim logins, how do I read ONLY tims line's admin status.

Currently I have a Login UDF. for that UDF I return something I named Loginstatus. If the login status = 1 . It will run the current problem that I'm trying to solve which is displaying the user adminstatus's discount rate. So how am I suppose to display the line of the user that logged in.

Here is the simplified explanation of my program. The user will login ( the program will see if everything matches up[username/password] then return loginstatus =1 if the user login successfully) Once the user logs in the program will bring up a menu which will have 2 options.

1. it will let the user check it's current discount rate.
2. quit.

View 2 Replies View Related

C++ :: How To Output A Table

Oct 1, 2014

How would I output a table in C++? I did it a while ago, but I do not remember how, nor do I have the source for the program I did it in.

View 2 Replies View Related







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