Mar 17, 2011 at 11:57am UTC
This is my code so far
I want the program to chose between a diameter from 0.5 to 3 mm or 3 to 6mm and pick the correct tolklass and display it in cout diam and tolklass.
If i pick a diameter between 0.5 to 3 the tk would be 0.03
If i pick a diameter between 3 to 6 the tk would be 0.07
Can anyonr help me to solve this please.
/* Toleransklass*/
#include <stdlib.h>
#include <iostream>
#include <string>
#include <cfloat>
#include <iomanip>
using namespace std;
int main()
{
string tk;
float diam,tolklass;
cout << "Enter diameter/l\x84ngd ";
cin>> diam;
cout << "f m c eller v ";
cin>> tk;
if(diam<=3 && diam >=0.50)
if (tk=="f")tolklass =0.01;
if (tk=="m")tolklass =0.02;
if (tk=="c")tolklass =0.03;
if (tk=="v")tolklass =0.04;
else if(diam<=6 && diam >=3)
if (tk=="f")tolklass =0.05;
if (tk=="m")tolklass =0.06;
if (tk=="c")tolklass =0.07;
if (tk=="v")tolklass =0.08;
cout <<"\n\n";
cout <<"Diameter "<< setprecision (4) << diam << " " << setprecision (4) <<tolklass;
cout <<"\n";
system ("pause");
return 0;
}
Mar 17, 2011 at 12:16pm UTC
Wrap these
1 2 3 4
if (tk=="f" )tolklass =0.01;
if (tk=="m" )tolklass =0.02;
if (tk=="c" )tolklass =0.03;
if (tk=="v" )tolklass =0.04;
and these
1 2 3 4
if (tk=="f" )tolklass =0.05;
if (tk=="m" )tolklass =0.06;
if (tk=="c" )tolklass =0.07;
if (tk=="v" )tolklass =0.08;
in braces
http://www.cplusplus.com/doc/tutorial/control/
Last edited on Mar 17, 2011 at 12:18pm UTC
Mar 17, 2011 at 12:27pm UTC
Thanks for yor kind help. Thats was easy. Thanks once again