why the output value have e+007??? please help me.





this is my coding
#include <iostream>
#include <cstring>
#include <fstream>

#define PI 3.14

using namespace std;

void calculate_cone(double,double);
void calculate_sphere(double,double);
void calculate_cylinder(double,double);
void calculate_pyramid(double,double,double);
void calculate_cuboid(double,double,double);

void main()
{
char shape1[20],answer[4];
double a,b,c;

cout<<"========\t\t===================================\n";
cout<<" TYPE\t\t\t\tCALCULATION FORMULA\n";
cout<<"========\t\t===================================\n";
cout<<"\nCONE\t\t\t1/3 x PI X radius x radius x height\n";
cout<<"SPHERE\t\t\t4/3 x PI x radius x radius x radius\n";
cout<<"CYLINDER\t\tPI x radius x radius x height\n";
cout<<"PYRAMID\t\t\t1/3 x width x length x height\n";
cout<<"CUBOID\t\t\twidth x length x height\n";

do
{
cout<<"\n\nEnter the shape (Cone, Sphere, Cylinder, Pyramid or Cuboid): ";
cin>>shape1;

if(strcmp(shape1,"Cone")==0 || strcmp(shape1,"cone")==0)
{
cout<<"\nEnter the radius(m): ";
cin>>a;
cout<<"\nEnter the height(m): ";
cin>>b;

calculate_cone(a,b);
}

else if(strcmp(shape1,"Sphere")==0 ||strcmp(shape1,"sphere")==0)
{
cout<<"\nEnter the radius(m): ";
cin>>a;
b=1;

calculate_sphere(a,b);
}

else if(strcmp(shape1,"Cylinder")==0 || strcmp(shape1,"cylinder")==0)
{
cout<<"\nEnter the radius(m): ";
cin>>a;
cout<<"\nEnter the height(m): ";
cin>>b;

calculate_cylinder(a,b);
}

else if(strcmp(shape1,"Pyramid")==0 || strcmp(shape1,"pyramid")==0)
{
cout<<"\nEnter the width(m):";
cin>>a;
cout<<"\nEnter the length(m):";
cin>>b;
cout<<"\nEnter the height(m):";
cin>>c;

calculate_pyramid(a,b,c);
}

else if(strcmp(shape1,"Cuboid")==0 || strcmp(shape1,"cuboid")==0)
{
cout<<"\nEnter the width(m):";
cin>>a;
cout<<"\nEnter the length(m):";
cin>>b;
cout<<"\nEnter the height(m):";
cin>>c;

calculate_cuboid(a,b,c);
}

else
{
cout<<"\n\nNot a valid input." ;
}

cout<<"\n\nContinue(Yes or No): ";
cin>>answer;

while (strcmp(answer,"Yes")!= 0 && strcmp(answer,"yes")!= 0 && strcmp(answer,"No")!=0 &&strcmp(answer,"no")!=0 )
{
cout << "Invalid input, please type 'Yes' or 'No'" << endl;
cout << "Continue: "; cin >> answer;
}
}
while(strcmp(answer,"Yes")==0 || strcmp(answer,"yes")==0);
cout<<"\n---------------------------------------------------\n";
}

void calculate_cone(double x, double y)
{
double volume_cone;
double cone_liter;

volume_cone = 0.33 * PI * x * x * y;
cone_liter = volume_cone * 1000;

ofstream theFile("volume.txt", ios::app);
theFile << "Cone" << "\t\t" << volume_cone << "m3\t" << cone_liter << "liter\t" << endl;
theFile.close();

cout<<"\nThe volume of this cone is "<<volume_cone<<" m3 equal to "<<cone_liter<<" liter \n\n";
}

void calculate_sphere (double x, double y)
{
double volume_sphere;
double sphere_liter;

volume_sphere = 1.33*PI*x*x*x*y;
sphere_liter = volume_sphere * 1000;

ofstream theFile("volume.txt", ios::app);
theFile << "Sphere" << "\t\t" << volume_sphere << "m3\t" << sphere_liter << "liter\t" << endl;
theFile.close();

cout<<"\nThe volume of this sphere is "<<volume_sphere<<" m3 equal to "<<sphere_liter<<" liter \n\n";
}

void calculate_cylinder(double x,double y)
{
double volume_cylinder;
double cylinder_liter;

volume_cylinder = PI * x * x * y;
cylinder_liter = volume_cylinder * 1000;

ofstream theFile("volume.txt", ios::app);
theFile << "Cylinder" << "\t" << volume_cylinder << "m3\t" << cylinder_liter << "liter\t" << endl;
theFile.close();

cout<<"\nThe volume of this cylinder is "<<volume_cylinder<<" m3 equal to "<<cylinder_liter<<" liter \n\n";
}

void calculate_pyramid(double x,double y,double z)
{
double volume_pyramid;
double pyramid_liter;

volume_pyramid = 0.33*x*y*z;
pyramid_liter = volume_pyramid * 1000;

ofstream theFile("volume.txt", ios::app);
theFile << "Pyramid" << "\t\t" << volume_pyramid << "m3\t" << pyramid_liter << "liter\t" << endl;
theFile.close();

cout<<"\nThe volume of this pyramid is "<<volume_pyramid<<" m3 equal to "<<pyramid_liter<<" liter \n\n";
}

void calculate_cuboid(double x,double y,double z)
{
double volume_cuboid;
double cuboid_liter;

volume_cuboid = x*y*z;
cuboid_liter = volume_cuboid * 1000;

ofstream theFile("volume.txt", ios::app);
theFile << "Cuboid" << "\t\t" << volume_cuboid << "m3\t\t" << cuboid_liter << "liter\t" << endl;
theFile.close();

cout<<"\nThe volume of this cuboid is "<<volume_cuboid<<" m3 equal to "<<cuboid_liter<<" liter \n\n";
}
Last edited on
Sounds like you need to learn the basics of C++. Here, http://www.cplusplus.com/doc/tutorial/ , a tutorial in this site just for what you need.

If you come across something you don't really understand, just ask the question.
#include<fstream>
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

void getColorCode(char colorCode[]);
long getResistorValue(char colorCode[]);
void getColorCode1 (char colorCode1 []) ;
long getResistorValue1 (char colorCode1 []) ;
char colorCode [3] ;
char colorCode1 [4] ;


int main (void)

{ int d ;
long f_value =0 ;
long f_value1 =0 ;
char color[20] ;
char i [10] ;
char j [10] ;
char k [10] ;
char m [10] ;
char t [10] ;
char cont ;
ifstream infile1("Mini.txt",ios::in) ;

cout<<"\t\t\tResistor Color Codes"<<endl ;
cout<<"\t\t\t********************"<<endl ;
cout<<"Color "<<setw(10)<<" 1st band"<<setw(10)<<" 2nd band"<<setw(10)<<"3rd band"<<setw(10)<<"10*(x)"<<setw(10)<<" Tolerance(+ -)"<<endl<<endl;
if (!infile1 )
{
cout << "Unable to open file";
exit(1);
}

while(infile1>>color>>i>>j>>k>>m>> t)
{
cout<<color<<setw(10)<< i <<setw(10)<< j <<setw(10)<< k <<setw(10)<< m <<setw(10)<< t <<endl;
}

infile1.close() ;

cout<<"\t(Enter color code according to table above,\n\ti.e for Black,please enter 'B')"<<endl ;
do{cout<<"Choose either four band color code or five band color code :"<<endl ;
cin>>d ;
if (d==4)
{ cout<<"\t---><Four band color code><---"<<endl ;
cout<<"Please enter the color code :"<<endl;
getColorCode (colorCode) ;

f_value = getResistorValue(colorCode) ;
cout<<"The resistor value with color code "<<colorCode[0]<<colorCode[1]<<colorCode[2]<<" is "<<f_value<< " Ohm "<<endl ;
cout<<"Continue?(Y/N) :"<<endl;
cin>>cont ;
}
else if(d==5)
{ cout<<"\t---><Five band color code><---"<<endl ;
cout<<"Please enter the color code :"<<endl;
getColorCode1 (colorCode1) ;

f_value1 = getResistorValue1(colorCode1) ;
cout<<"The resistor value with color code "<<colorCode1[0]<<colorCode1[1]<<colorCode1[2]<<colorCode1[3]<<" is "<<f_value1<< " Ohm "<<endl ;
cout<<"Continue?(Y/N) :"<<endl;
cin>>cont ;
}
else
{ cout<<"Sorry,please RE-ENTER a valid code"<<endl;
cout<<"Continue?(Y/N) :"<<endl;
cin>>cont ;
}
}while (cont != 'N') ;
}


void getColorCode (char colorCode[])
{
int i;
for(i = 0; i < 3; i++)
cin>>colorCode[i];
}

long getResistorValue (char colorCode [])
{
int i;
double multiplier;
char band_color;
long value;
double colorValue[3];

for(i = 0; i < 3; i++)
{
band_color=colorCode[i];
switch (band_color)
{
case('B'): colorValue[i] = 0;
break;
case('N'): colorValue[i] = 1;
break;
case('R'): colorValue[i] = 2;
break;
case('O'): colorValue[i] = 3;
break;
case('Y'): colorValue[i] = 4;
break;
case('G'): colorValue[i] = 5;
break;
case('L'): colorValue[i] = 6;
break;
case('V'): colorValue[i] = 7;
break;
case('E'): colorValue[i] = 8;
break;
case('W'): colorValue[i] = 9;
break;

default: cout<<"Please re-enter a valid code"<<endl;
break ;
}
}

multiplier = pow( 10, (double) colorValue[2]);

value = (((colorValue[0]*10) + colorValue[1]) * multiplier);
return value ;

}


void getColorCode1 (char colorCode1 [])
{
int i;
for(i = 0; i < 4; i++)
cin>>colorCode1[i];
}
long getResistorValue1 (char colorCode1 [])
{
int i;
double multiplier;
char band_color;
long value;
double colorValue[4];

for(i = 0; i < 4; i++)
{
band_color=colorCode1[i];
switch (band_color)
{
case('B'): colorValue[i] = 0;
break;
case('N'): colorValue[i] = 1;
break;
case('R'): colorValue[i] = 2;
break;
case('O'): colorValue[i] = 3;
break;
case('Y'): colorValue[i] = 4;
break;
case('G'): colorValue[i] = 5;
break;
case('L'): colorValue[i] = 6;
break;
case('V'): colorValue[i] = 7;
break;
case('E'): colorValue[i] = 8;
break;
case('W'): colorValue[i] = 9;
break;
case('D'): colorValue[i] = -1 ;
break ;
case('S'): colorValue[i] =-2 ;
break ;
default: cout<<"Please re-enter a valid code"<<endl;
break ;
}
}

multiplier = pow( 10, (double) colorValue[3]);

value = (((colorValue[0]*100) +(colorValue[1]*10)+colorValue[2]) * multiplier);
return value ;

}

i done this coding.. but still cant run.... can you check this coding and give me a solution...
Last edited on
I will surely check it out once you put it inside code tags. :D

http://cplusplus.com/articles/z13hAqkS/

That should explain how to use them. It's just that I read formatted code everyday, and unformatted code is just so hard to read.
You pass C arrays as parameters?
If you try to write data in forbidden memory your program will crash.
Since you're a C++ programmer, you should learn to use what C++ provides.

Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <deque>

std::deque<int> read_colors()
{
    std::deque<int> colors;
    int user_color = 0;

    // read user_color int's from user
    // while (...) {
    colors.push_back(user_color);
    // }

    return colors;
}

int main()
{
// ...
std::deque<int> C = read_colors();
// ...
}


You can read more about Containers here, and choose the one best suited:
http://cplusplus.com/reference/stl/
Topic archived. No new replies allowed.