Solved

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

Posted on 2008-10-14
4
194 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

776 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