C/C++ :: Why Does Printf Not Print After A While Or For Loop

Jul 1, 2012

I would like the following code to print: "Why doesn't this print?" and "I would like to print the sum of nc: 5". What am I doing wrong.

#include <stdio.h>  
//Use to test ideas and formats//  
main() {
    int c, nc;      
    nc = 0;  

[code]....

My result as compiled by gcc -o testing testing.c

This prints.

test
t1,e2,s3,t4,
5,

I have not figured out how to sum and print as the above code indicates, which complicates my ability to do many of the exercises in "The C Programming Language". I am using a MacBook gcc compiler and X code as well. I cannot get the last two printf functions to work. I did the temperature example with "while (fahr <= upper)" and the printf printed.

View 7 Replies


ADVERTISEMENT

C :: Printf Doesn't Print On Screen

May 23, 2013

This code runs. However, when I run it, the text from printf doesn't appear until after I type in the two numbers.

I use Wascana, will it run correctly on other compilers?

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
fflush(stdout);

[Code].....

And this is how it turns out on the screen:

Code:

6
3

What size is the die:

how many dice to roll:

Numbers are 3d6
Rolling die no.1...
RolledDie: 4 DieTotal: 4
Rolling die no.2...
RolledDie: 5 DieTotal: 9
Rolling die no.3...
RolledDie: 5 DieTotal: 14

The total is: 14

View 4 Replies View Related

C/C++ :: How To Print Results On Screen Without Using Printf

Jun 26, 2013

how to print the result on screen without using printf in C...?

View 6 Replies View Related

C/C++ :: Using Printf Statement To Print Certain Number Of Spaces

Sep 1, 2014

is there a to use printf to print certain number of blank spaces, where the number is derived from the output of a function?

for(m=low; m<=high;m++)
{
printf("t=%2d %'f(m)-1's %3c
", m, ' ',*);
}

this is suppose to output

t=-3 *
t=-2 *
t=-1
.
.
.

This is supposed to output t=m and then m is plugged into a function say for -3, plugging it into function f gives 23, well i want 22 blank spaces and then a asterik and go to next line. that is why i put -1 after %'f(m)-1's i

The asterisk appear right next to the t value here but they are way to the right of it when i made this post.

View 2 Replies View Related

C++ :: Printf In Loop

Jul 17, 2013

I am having trouble with the printf in this function:

Code:
void print_orig_array(char string_array[MAX_PEOPLE][NAME_SIZE], int ages[MAX_PEOPLE], int length) {
int counter;
printf("Original list");
printf("

[URL] ....

Here is the output:

Am I missing something with the format specifier? How do I fix the 84 that gets pushed out?

View 2 Replies View Related

C/C++ :: How To Print A Huge Unsigned Long Int Number By Using Printf

Oct 29, 2012

Here is the code:

int unsigned long a,b;
scanf("%lu",&a);
scanf("%lu",&b);
printf("%lu",a*b);

suppose we input a very large number on a and b (no more than 1000 digit)

like a = 1234567890123456789012345678901234567890

and b = 9876543210987654321098765432109876543210

it outputs 1, why is it?

It is probably the answer is too big, is there any way to show a*b?

View 1 Replies View Related

C :: Printf In A While Loop Is Printing Twice Instead Of Once

Sep 21, 2013

I have a minor issue in my program:

Code:
char Answer;
printf("
To search for a specifc word, type (Y), to use a dictionary file, type (N):

[Code] .....

When I run the program, it gives:

To search for a specific word, type (Y), to use a dictionary file, type (N):

Sorry, the given input is invalid, please try again:

I can then input the number. Typing n,N,y or Y goes to the next part of the program without any problems, but if I type something else, I get:

Sorry, the given input is invalid, please try again:

Sorry, the given input is invalid, please try again:

I've fiddled about with the code for a while now, but nothing I do seems to work. What is causing it to be printed twice, or why the first getchar() is ignored.

View 2 Replies View Related

C :: Can't Get Strings To Print When Using For Loop

Mar 6, 2015

I am making a program that takes the user's family names, their ages, and where they live. At the end I will be eventually averaging out their age and also printing the names of anyone who lives in Kansas.

I can't seem to get the Kansas part to work properly though.. When I execute the code, everything else works perfectly, but the Kansas part doesn't even print. Is there something different I need to do when strings are involved rather than integers/floats?

Code:

#include <stdio.h>
int main ()
{
/* variable definition: */

[Code].....

View 6 Replies View Related

C/C++ :: Cannot Get Strings To Print When Using For Loop

Mar 24, 2015

I am making a program that takes the user's family names, their ages, and where they live. At the end I will be eventually averaging out their age and also printing the names of anyone who lives in Kansas.

I can't seem to get the Kansas part to work properly though.. When I execute the code, everything else works perfectly, but the Kansas part doesn't even print. Is there something different I need to do when strings are involved rather than integers/floats?

#include <stdio.h>
int main () {
/* variable definition: */

[Code].....

View 3 Replies View Related

C/C++ :: Print Series Of Text From Loop

Sep 29, 2014

I'm attempting to print a series of text from this loop, but for some reason all I am getting is the sum total and the number 1, like this

1 5175.11

When I want to get it for each iteration of the loop. I've cycled over this and compared it to my other loops I've used and I'm lost as to why this isn't working. I also tried using a do while but that didn't work as well.

for (double total1 = 0; total1 < goal; total1 + save_amt) {
total2 = ((factor - one) * save_amt);
total3 = (total2 / fr_interest);
total1 = total1 + total3;
months_dis = (months_dis + one);
cout << months_dis << " " << total1 << endl;
}

View 14 Replies View Related

C :: Print Triangle Pattern Using One Loop And Recursion?

Dec 18, 2013

Q.print triangle pattern using one loop and recursion

eg: 5

Code:

#include <stdio.h>#include <conio.h>
void pattern(int n,int N) {
int i,c=1;

[Code]....

View 8 Replies View Related

C/C++ :: Print 10101 And 01010 Series Using For Loop

Apr 11, 2014

10101
01010
10101
01010

I want print above series using for loop.

View 2 Replies View Related

C++ :: Print ASCII Characters - Limit In For Loop

May 1, 2015

#include<iostream>
#include<conio.h>
using namespace std;
int main(void){
clrscr();

[Code] ....

I am trying to print ascii characters but problem is If i put a limit in for loop to 255 or more than 126 the output don't stop it keeps on going

I know there is another way to this program but what i want to know this why this happen in this logic....it doesn't happen if a<=125 or less then 125.

View 7 Replies View Related

C++ :: Count Controlled Loop Than Can Print Char

Sep 27, 2012

Write a count controlled loop than can print "i" char. The user is supposed to input a integer and that integer is how many asterisks there is on the blade, in this case it is 5.

* *
** ** **---------------
*******
** ** **
* ** * -10 Rows high
** -blade always connects on second row of handle
**
**
**
**------------------

These are the steps he told us to do it in.

1) *
**
***
****
*****

2) *
**
***
****
*****
****
***
**
*

3) * *
** **
*** ***
**** ****
**********

4) * *
** **
*** ***
**** ****
**********
**** ****
*** ***
** **
* *

5)* *
** ** **
*******
** ** **
* ** *
**
**
**
**
**

View 4 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/C++ :: For Loop To Print Given Character Number Of Times Specified By Integer

Feb 11, 2014

The function uses a "for" loop to print the given character the number of times specified by the integer.

How can I make a for loop to do that?

So.. my code looks like this:

// cpp : Defines the entry point for the console application
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void printMyInteger(int myInteger, char myChar) {

[Code] ....

So.. here is my error:

Error1error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
Error2error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
3IntelliSense: expected an expressiond:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp107Week 6

View 3 Replies View Related

C# :: Infinite Loop Random Boolean Print Statement

Feb 19, 2014

I am working on a small simple program my program fills up a air plane with customers there is 2 levels 1 and 2 and it will put that person in the spot depending on being picked.

So far i made a boolean airplane with 10 spots I can enter 1 person into the airplane with no problem but then after he sits down i get a infinite loop? I assume i maybe have to use the continue statement I feel like there is something simple that im missing i want to add more people. here is what i have

class Program
{
static void Main(string[] args)
{ bool[] planeSeats = {false, false, false, false, false, false, false, false, false, false };

[Code]......

View 1 Replies View Related

C++ :: Print Each Percent Of Loop Breaks Down For Large Loops?

Feb 22, 2012

I'm trying to make a percentage counter inside a loop, printing each completed percent of the loop as it goes. I've managed to write such code, but when I run it the percentage output breaks down (becomes negative!) for large loops. I have an example below.

Code:
#include <iostream>
#include <sstream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
using namespace std ;
int main() {

[code].....

Compiling and running the above yields the output:

Code:

...1% ...2% ...3% ...4% ...5% ...6% ...7% ...8% ...9% ...10% ...11% ...12% ...13% ...14% ...15% ...16% ...17% ...18% ...19% ...20% ...21% ...-21% ...-20% ...-19% ...-18% ...-17% ...-16% ...-15% ...-14% ...-13% ...-12% ...-11% ...-10% ...-9% ...-8% ...-7% ...-6% ...-5% ...-4% ...-3% ...-2% ...-1% ...0% ...1% ...2% ...3% ...4% ...5% ...6% ...7% ...8% ...9% ...10% ...11% ...12% ...13% ...14% ...15% ...16% ...17% ...18% ...19% ...20% ...21% ...-21% ...-20% ...-19% ...-18% ...-17% ...-16% ...-15% ...-14% ...-13% ...-12% ...-11% ...-10% ...-9% ...-8% ...-7% ...-6% ...-5% ...-4% ...-3% ...-2% ...-1% ...0% ...1% ...2% ...3% ...4% ...5% ...6% ...7% ...8% ...9% ...10% ...11% ...12% ...13% ...14%...100%

If I change the value of N to 1e7 instead of 1e8, the output is correct however!

Code:
...1% ...2% ...3% ...4% ...5% ...6% ...7% ...8% ...9% ...10% ...11% ...12% ...13% ...14% ...15% ...16% ...17% ...18% ...19% ...20% ...21% ...22% ...23% ...24% ...25% ...26% ...27% ...28% ...29% ...30% ...31% ...32% ...33% ...34% ...35% ...36% ...37% ...38% ...39% ...40% ...41% ...42% ...43% ...44% ...45% ...46% ...47% ...48% ...49% ...50% ...51% ...52% ...53% ...54% ...55% ...56% ...57% ...58% ...59% ...60% ...61% ...62% ...63% ...64% ...65% ...66% ...67% ...68% ...69% ...70% ...71% ...72% ...73% ...74% ...75% ...76% ...77% ...78% ...79% ...80% ...81% ...82% ...83% ...84% ...85% ...86% ...87% ...88% ...89% ...90% ...91% ...92% ...93% ...94% ...95% ...96% ...97% ...98% ...99%...100%

View 5 Replies View Related

C++ :: Print In Asterisks Oval / Arrow And Diamond Using For Loop And If Statements

Jan 15, 2015

#include <iostream>
using namespace std;
int main(){
return 0;
}

this is my main functions. I have problem making a program that prints in asterisks an oval, arrow and a diamond using for loop and if statements.

View 1 Replies View Related

Visual C++ :: Use For Loop To Read Certain Data From Txt File And Print To Console

Sep 28, 2014

I'm new to programming and i'm trying to do a certain task. I want to use a for loop to read certain data from a txt file and print them to a console. I'm trying to read student names and their grades.

Something like
3 // 3 represents the number of students.
George 97
Sarah 70
Maya 88

The data may vary but it's always in this format.

View 14 Replies View Related

C :: Loop Statement To Print Numbers From 1 To 10 In Reverse Order Separated By Star

Apr 21, 2013

Write a for loop statement to print the numbers from 1 to 10 in reverse order separated by star :

10*9*8*7*6*5*4*3*2*1

i try to do it but it show me like this :

10*9*8*7*6*5*4*3*2*1*

how do i write to show me like the first one ?

View 10 Replies View Related

C :: ANSI Program To Print Out Each Command Line Argument On Separate Line Using For Loop

Mar 5, 2013

I need to write a ANSI program to print out each command line argument on a separate line using a for-loop. also it need to print the name of the executable .so far I have

Code:

#include <stdio.h>
int main(int argc, char **argv) {
int i;
printf("")

[code]....

View 1 Replies View Related

C :: How To Printf Floats

Jan 30, 2013

I am having a hard time with some of my homework, specifically regarding how to printf floats. I can't seem to print the number i want out using float, it just becomes a jumbled mess.

Code:
#include <stdio.h>
#define TICKER "LRCX"
#define PURCHASE_DATE "01/02/13"
#define SELL_DATE "01/30/13"
#define INVESTMENT_AMOUNT "10,000.00"

[Code] .....

Thats the code I currently have, I've probably tried everything to get the number to come out, but I just cant seem to figure it out. It should look like this, but with different numbers and stock:

Stock: MCD Buy Date: 01/02/13 Sell Date: 01/29/13 Buy Share Price: $89.40 Sell Share Price: $91.50 Shares Purchased: 111.86

Amount of Investment: $10,000.00 Value of Shares Sold: $10,234.90 Amount of Gain/Loss: $234.90 Percent Gain/Loss: 2.35%

However, this is how mine turns out:

Code::Blocks
Enter share purchase price for LRCX=>23
Enter the selling price for LRCX=>23

Stock: LRCX
Buy Date: 01/02/13
Sell Date: 01/30/13
Buy Share Price: -1.#R
Sell Share Price: -1.#R
Shares Purchased: -1.#R

Amount of Investment: 10,000.00
Value of Shares Sold:-1.#R
Amount of Gain/Loss:-1.#R
Percent Gain/Loss:-1.#R%

Process returned 0 (0x0) execution time : 2.864 s
Press any key to continue.

View 3 Replies View Related

C :: How To Printf A Struct

Apr 22, 2014

Code:

#include <stdio.h>
struct database {
int id_number;
int age;
float salary;

[Code] ....

When I compile, I get an error:
test.c|18|error: incompatible type for argument 1 of 'printf'|
note: expected 'const char *' but argument is of type 'float'|

I thought employee.salary is a float but the compiler expected 'const char'. How do I make this work?

View 4 Replies View Related

C++ :: From Printf To String

May 6, 2013

I have the following line of the code. Now I want to save the content to a string. Is there a quick way for me to do the conversion using the same arguments/codes of printf?

printf ("Some different radixes: %d %x %o %#x %#o
", 100, 100, 100, 100, 100);

View 3 Replies View Related

C/C++ :: How To Skip The Value In Printf

Sep 5, 2014

#include<stdio.h>
void main()
{
int i=6;
printf("%d %*d
",i,i+9);
}

what is the out put?

View 2 Replies View Related







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