Here the code I have so far:
#include <stdio.h>
#include <math.h>
void main()
{
double comprLoad;
double comprStress;
double d,area;
char type[20];
const double PI= 3.14;
printf("Enter material type: ");
scanf("%s",type);
printf("Enter compression load: ");
scanf("%lf",&comprLoad);
comprStress = 25000;
area =comprLoad/comprStress;
d=2*sqrt(area/PI);
printf("\n\nType of the material: %s\n",type);
printf("Compression Load: %.2lf\n",comprLoad);
printf("Allowable stress: %.2lf\n",comprStress);
printf("Diameter: %.2lf",d);
comprStress=15000;
area =comprLoad/comprStress;
d=2*sqrt(area/PI);
printf("\n\nAllowable stress: %.2lf\n",comprStress);
printf("Diameter: %.2lf",d);
comprStress=20000;
area =comprLoad/comprStress;
d=2*sqrt(area/PI);
printf("\n\nAllowable stress: %.2lf\n",comprStress);
printf("Diameter: %.2lf",d);
getchar ();
return;
}
For some reason it exits prior to performing any of the calculations. Not sure why. Any and aall help is greatly appreciated. It will allow me to enter the material type and the compression load but quickly exits after that.
---------- Post added at 10:42 AM ---------- Previous post was at 09:35 AM ----------
What the heck am I doing wrong?
9 replies to this topic
#1
Posted 17 January 2012 - 10:42 AM
|
|
|
#2
Posted 17 January 2012 - 10:54 AM
I copied your code into a new CodeBlocks console project. It displayed everything as expected:
Enter material type: test
Enter compression load: 20
Type of the material: test
Compression Load: 20.00
Allowable stress: 25000.00
Diameter: 0.03
Allowable stress: 15000.00
Diameter: 0.04
Allowable stress: 20000.00
Diameter: 0.04
Process returned 0 (0x0) execution time : 4.735 s
Press any key to continue.
Enter material type: test
Enter compression load: 20
Type of the material: test
Compression Load: 20.00
Allowable stress: 25000.00
Diameter: 0.03
Allowable stress: 15000.00
Diameter: 0.04
Allowable stress: 20000.00
Diameter: 0.04
Process returned 0 (0x0) execution time : 4.735 s
Press any key to continue.
#3
Posted 17 January 2012 - 01:17 PM
Im trying to get this to work in Visio......any idea why it wouldnt work there?
#4
Posted 17 January 2012 - 04:05 PM
Visio? or Visual Studio?
#5
Posted 17 January 2012 - 04:56 PM
Oh hell my bad, visual studio.....something doesnt seem right about the program
#6
Posted 17 January 2012 - 05:13 PM
Try either turning precompiled headers off or you can #include <stdafx.h> . I'm just assuming here since lespauled said it ran fine.
#7
Posted 18 January 2012 - 06:18 AM
At what point does it exit?
---------- Post added at 02:18 PM ---------- Previous post was at 02:14 PM ----------
stdafx.h is not a standard header. I've been working with C for years and have become familiar with the C Standard Library, the POSIX API, and to some extent the Windows API, and I have never even heard of stdafx.h. I'm guessing it's a component of some specific framework, and only works for that framework. In any case, you shouldn't use it.
---------- Post added at 02:18 PM ---------- Previous post was at 02:14 PM ----------
invokeLater said:
Try either turning precompiled headers off or you can #include <stdafx.h> . I'm just assuming here since lespauled said it ran fine.
stdafx.h is not a standard header. I've been working with C for years and have become familiar with the C Standard Library, the POSIX API, and to some extent the Windows API, and I have never even heard of stdafx.h. I'm guessing it's a component of some specific framework, and only works for that framework. In any case, you shouldn't use it.
Programming is a journey, not a destination.
#8
Posted 18 January 2012 - 06:27 AM
stdafx.h is a VS thingy, you should include it.
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#9
Posted 18 January 2012 - 06:58 AM
If you're using Visual Studio, put a breakpoint on the first line, and hit F10 to go step by step through the program.
But this works in Visual Studio:
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
#include <iostream>
void main()
{
double comprLoad;
double comprStress;
double d,area;
char type[20];
const double PI= 3.14;
printf("Enter material type: ");
scanf("%s",type);
printf("Enter compression load: ");
scanf("%lf",&comprLoad);
comprStress = 25000;
area =comprLoad/comprStress;
d=2*sqrt(area/PI);
printf("\n\nType of the material: %s\n",type);
printf("Compression Load: %.2lf\n",comprLoad);
printf("Allowable stress: %.2lf\n",comprStress);
printf("Diameter: %.2lf",d);
comprStress=15000;
area =comprLoad/comprStress;
d=2*sqrt(area/PI);
printf("\n\nAllowable stress: %.2lf\n",comprStress);
printf("Diameter: %.2lf",d);
comprStress=20000;
area =comprLoad/comprStress;
d=2*sqrt(area/PI);
printf("\n\nAllowable stress: %.2lf\n",comprStress);
printf("Diameter: %.2lf",d);
std::getchar();
return;
}
But this works in Visual Studio:
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
#include <iostream>
void main()
{
double comprLoad;
double comprStress;
double d,area;
char type[20];
const double PI= 3.14;
printf("Enter material type: ");
scanf("%s",type);
printf("Enter compression load: ");
scanf("%lf",&comprLoad);
comprStress = 25000;
area =comprLoad/comprStress;
d=2*sqrt(area/PI);
printf("\n\nType of the material: %s\n",type);
printf("Compression Load: %.2lf\n",comprLoad);
printf("Allowable stress: %.2lf\n",comprStress);
printf("Diameter: %.2lf",d);
comprStress=15000;
area =comprLoad/comprStress;
d=2*sqrt(area/PI);
printf("\n\nAllowable stress: %.2lf\n",comprStress);
printf("Diameter: %.2lf",d);
comprStress=20000;
area =comprLoad/comprStress;
d=2*sqrt(area/PI);
printf("\n\nAllowable stress: %.2lf\n",comprStress);
printf("Diameter: %.2lf",d);
std::getchar();
return;
}
#10
Posted 21 January 2012 - 10:21 PM
If it exits early, It possibly crashed. Can you enter in debug mode so you can see which line number it crashes?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









