Solved

REALLY EASY I don't know why this won't enter the for loop

Posted on 2008-10-14
4
192 Views
Last Modified: 2010-04-21
I keep getting compiling errors on this and I'm about ready to throw my first right through the screen of this laptop.
#include <stdio.h>

#include <stdlib.h>

#include <time.h>
 

int main( void )

{

	int quantity = 1;

	int i = 1;

	srand(time(NULL));
 

	printf( "How many Quick Picks do you want?\n" );

	scanf( "%d\n", &quantity );
 

	for ( i = 1; i <= quantity i++ ) 

	{

		printf( "Quick Pick: %d\n", 1 + (rand() % 54));

	}

			

	return 0;  /* program executed successfully */

}

Open in new window

0
Comment
Question by:Doomtomb
  • 2
  • 2
4 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 22718157
for ( i = 1; i <= quantity; i++ )
note ; after quantity
0
 

Author Comment

by:Doomtomb
ID: 22718161
Jeeze, I knew it was something dumb like that. I have attached what it is right now but for some reason, it won't enter the for loop. It prints asking the user, then you type a value like 2 and enter and nothing happens.
#include <stdio.h>

#include <stdlib.h>

#include <time.h>
 

int main( void )

{

	int quantity;

	int i;

	srand( time( NULL ) );
 

	printf( "How many Quick Picks do you want?\n" );

	scanf( "%d\n", &quantity );
 

	for ( i = 1; i <= quantity; i++ ) {

		printf( "Quick Pick: %d\n", 1 + (rand() % 54));

	}

			

	return 0;  /* program executed successfully */

}

Open in new window

0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 total points
ID: 22718172
>scanf( "%d\n", &quantity );

scanf has its quirks ... remove the \n in the format string ...
preferred method of inputting is to use fgets to read in a line and then use atoi/strtol to convert.
0
 

Author Closing Comment

by:Doomtomb
ID: 31506195
Works great. My programming teacher forces us to use scanf. It sucks. I HATE THIS!!!!! I GOT SO MAD!!!!!!! THANK YOU!!!!!! *ANGRY VOICE*
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumNumber challenge 16 99
countX 22 70
changeXy challenge 13 58
How to access ANSI/IEEE Std 754 or equivalent information ? 3 11
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now