stackoverflow1453

Programming&&Games&&Life

Archive for Dev-C++

Elementary School Multiplication teaching program crashed Windows, details below

When I run below code https://stackoverflow1453.wordpress.com/2013/04/17/write-a-program-that-will-help-an-elementary-school-student-learn-multiplication/ it works until 3 iterations of simple game but after the 3rd iteration CPU usage shoots to 90% and instantly crashes. Even console is terminated but below programs exe is seen in windows task list. I have to manually delete it for windows CPU to return to 3% levels.  

What caused this? I searched forums and I run the same code on Visual Studio 2008 without any problems. Then I turned my head on Dev-C++. I do not have the latest version . I had  DevC++ (Version 4.9.9.2 Orwell Update 5.3.0.3 which uses TDM-GCC 4.6.1.64 compiler). I found this site which isupdated and official site of Dev-C++. http://orwelldevcpp.blogspot.com/2013/03/dev-c-541-released.html  

I downloaded DEV-C++ 5.4.1 RC4. This time code worked okay. I do not know what caused the problem with former version but I am happy that I have a working IDE now. 

Note: I changed Compiler to MinGW GCC 4.7.2 32-bit. In former version it was TDM-GCC 64 bit compiler.

 

Maybe you can tell me what caused the problem.

 

Dev-C++ does not work in 32 bit Windows default. What is the solution?

Compiling for 32bit using TDM-GCC x64

To force 32bit on all new projects and non-project compiles, go to Tools >> Compiler Options and select the ‘TDM-GCC 32bit’ profile. This profile will pass -m32 and use lib32 by default.

To force 32bit on already created projects, go to Project >> Project Options >> Compiler and select the ‘TDM-GCC 32bit’ compiler profile.

Write a program that reads five numbers (each between 1 and 30). For each number read, your program should print a line containing that number of adjacent asterisks.

Interesting thing about this program is if you don’t know what is STDIN and how scanf works, program is hard to understand. I asked this in stackoverflow. It is better if you study the below post in conjunction with this program.

http://stackoverflow.com/questions/15091381/why-is-this-how-number-variable-gets-5-different-values-how-does-it-remember

/*
	Name:
	Copyright:
	Author: StackOverflow1453
	Date: 26.02.2013 15:56:43
	Description:
	One interesting application of computers is drawing graphs and bar charts 
	(sometimes called “histograms”). Write a program that reads five numbers 
	(each between 1 and 30). For each number read, your program should print a 
	line containing that number of adjacent asterisks. 
	For example, if your program reads the number seven, it should print *******.
	
	Program output:
		
		Enter 5 numbers between 1 and 30: 28 5 13 24 7
		****************************
		*****
		*************
		************************
		*******
*/

#include <stdio.h>

int main(void){
	
	int number;
	int i;
	int j;
	
	printf("Enter 5 numbers between 1 and 30:");
	
	for(i=1;i<=5;i++){
		
		scanf("%d",&number);
		
		for (j=1;j<=number;j++)
			printf("*");
		printf("\n");
		
	}
	
	
}

Collecting money becomes increasingly difficult during periods of recession, so companies may tighten their credit limitsto prevent their accounts receivable (money owed to them) from becoming too large. In response to a prolonged recession, one com-pany has cut its customer’s credit limits in half. Thus, if a particular customer had a credit limit of $2000, this customer’s credit limitis now $1000. If a customer had a credit limit of $5000, this customer’s credit limit is now $2500. Write a program that analyzesthe credit status of three customers of this company. For each customer you are given:a)The customer’s account numberb) The customer’s credit limit before the recessionc)The customer’s current balance (i.e., the amount the customer owes the company).Your program should calculate and print the new credit limit for each customer and should determine (and print) which cus-tomers have current balances that exceed their new credit limits. Program Output: Enter account, limit, balance: 100 4000.00 2136.87 New credit limit for account 100 is 2000.00 Limit exceeded for account 100 Enter account, limit, balance: 200 10500.00 4927.39 New credit limit for account 200 is 5250.00 Enter account, limit, balance: 300 1000.00 750.00 New credit limit for account 300 is 500.00 Limit exceeded for account 300

/*
	Name:
	Copyright:
	Author: StackOverflow1453
	Date: 26.02.2013 15:45:14
	Description: Collecting money becomes increasingly difficult during periods 
	of recession, so companies may tighten their credit limitsto prevent their 
	accounts receivable (money owed to them) from becoming too large. 
	In response to a prolonged recession, one com-pany has cut its customer's 
	credit limits in half. Thus, if a particular customer had a credit limit of 
	$2000, this customer’s credit limitis now $1000. If a customer had a credit 
	limit of $5000, this customer's credit limit is now $2500. Write a program 
	that analyzesthe credit status of three customers of this company. 
	For each customer you are given:a)The customer’s account numberb)
	The customer’s credit limit before the recessionc)The customer’s current 
	balance (i.e., the amount the customer owes the company).Your program should 
	calculate and print the new credit limit for each customer and should 
	determine (and print) which cus-tomers have current balances that 
	exceed their new credit limits.
	
	Program Output:
		Enter account, limit, balance: 100 4000.00 2136.87
		New credit limit for account 100 is 2000.00
		Limit exceeded for account 100
	
		Enter account, limit, balance: 200 10500.00 4927.39
		New credit limit for account 200 is 5250.00
		
		Enter account, limit, balance: 300 1000.00 750.00
		New credit limit for account 300 is 500.00
		Limit exceeded for account 300
		
*/

#include <stdio.h>

int main(void){
	
	int account;
	float limit;
	float balance;
	
	printf("Enter account, limit, balance:");
	scanf("%d %f %f",&account,&limit,&balance);
	
	printf("New credit limit for account %d is %.2f. \n",account, limit/2);
	
	if(limit/2<balance)
		printf("Limit exceeded for account %d .\n",account);
		
	return 0;
	
}

How to add default source code to Dev-C++?

If you don’t want to include stdio.h everytime you start a code, you can order Dev-C++ to do this automatically everytime you open new empty source file.

Just go to

Tools
Editor Options
Code Insertion
Default Code

copy and paste this :

/*
	Name:
	Copyright:
	Author: Your name
	Date: <DATETIME>
	Description:
*/

#include <stdio.h>

int main(void)

Don’t forget the tick the checkbox up!
Thats all.