output showing 2.34777e-317 on the note pad

#include<iostream>
#include <stdlib.h>
#include<fstream>
#include<string>
using namespace std;

void Shape()
{

int numshape;

cout<<"\t\t\tShape for the cake !!! ";
cout<<"\n\n\t\tCylinder Cone Cube ";
cout<<"\n\t\t 1 2 3 ";
cout<<"\n\n\t\t\t Pyramid Cuboid ";
cout<<"\n\t 4 5";
cout<<"\n\nEnter the shape for the cake.\n ";
cin>>numshape;

switch(numshape)
{

case 1 :
cout<<"You have choose Cylinder";
break;

case 2 :
cout<<"You have choose Cone ";
break;

case 3 :
cout<<"You have choose Cube ";
break;

case 4 :
cout<<"You have choose Pyramid ";
break;

case 5 :
cout<<"You have choose Cuboid ";
break;

default : cout<<"It's in valid";

}

}


void typeName()
{


int numtype ,price, price1 = 35,price2 =45 ,price3 = 55,newprice, question,question2,kg,kg2,Totalkg;
double d;
cout<<"\t\t\t Type of Cake ";
cout<<"\nButter Cake\t\tChocolate cake\t\tCheese cake\n";
cout<<" 1\t\t\t\t2\t\t 3\n ";
cout<<"****************************************************\n\n";
cout<<"Please enter the type for the cake";

cin>>numtype;

switch(numtype)
{
case 1 :

cout<<"You have choosen butter cake \n";
cout<<"The price is RM"<<price1<<" per kg\n";
cout<<"Do you want to add more KG to your cake ?\n";
cout<<"Enter 11 for Yes and 12 for No\n ";
cin>>question;
switch(question)
{
case 11: cout<<"\nHow many KG do you want ?\n";
cin>>kg;
//process
Totalkg=1+kg;
d=price1*kg;
cout<<"\nYour cake now is "<<Totalkg<<"kg\n";
cout<<"The price is now\n"<<d;
break;

default:cout<<"\n error wrong input";
break;


case 2 :

cout<<"You have choosen Chocolate Cake\n ";
cout<<"The price is"<<price2<<"per kg\n";
cout<<"Do you want to add more KG to your cake ?\n";
cout<<"Enter 1 for Yes and 2 for No \n";
cin>>question;
//cleear kan nanti
if(question=1)
{
cout<<"\nHow many KG do you want ?\n";
cin>>kg;
Totalkg=1+kg;
d=price2*kg;
cout<<"\nYour cake now is "<<Totalkg<<"kg\n";
cout<<"The price is now "<<d;
}

else
cout<<"error wrong input\n";
break;

case 3 :

cout<<"You have choosen Cheese Cake \n";
cout<<"The price is"<<price3<<"per kg\n";
cout<<"Do you want to add more KG to your cake ?\n";
cout<<"Enter 1 for Yes and 2 for No \n";
cin>>question;
//cleear kan nanti
if(question=1)
{
cout<<"\nHow many KG do you want ?\n";
cin>>kg;
Totalkg=1+kg;
d=price3*kg;
cout<<"Your cake now is "<<Totalkg<<"kg\n";
cout<<"The price is now \n"<<d;
}

else
cout<<"error wrong input\n";
break;
}
}system("cls");
}


void Topping()
{
int numTopping ,totalamount, newprice;
double d;
cout<<"\tThe best topping in the world\n\n";
cout<<" Fresh Fruits\t\tToasted Coconut\n\n";
cout<<"\t1\t\t\t2 \n ";
cout<<" \n ";
cout<<"Toasted Nuts\t\tMini Chocolate Cake\n";
cout<<"\t3\t\t\t4 \n\n";

cout<<"Pick your favourite Topping number";
cin>>numTopping;

switch(numTopping)
{
case 1 :
cout<<"Fresh fruits will charge you RM5";
totalamount=5+d;
break;

case 2 :
cout<<"Toasted Coconut will charge you RM2";
totalamount=2+d;
break;

case 3 :
cout<<"Toasted Nuts will charge you RM6";
totalamount=6+d;
break;

case 4 :
cout<<"Mini Chocolate Cake will charge you RM4";
totalamount=4+d;
break;

}system("cls");
}




int main()
{
double newtotalamount,totalamount,numshape,numtype,numTopping;
ofstream myfile("Resit.txt");
if(myfile.is_open())
{

Shape();
system("cls");
typeName();
Topping();
newtotalamount=totalamount+(totalamount*0.7);
myfile<<"\t\tANY CAKE SHOP\n";
myfile<<"----------------------------------\n";
myfile<<"Type of Shape"<<numshape<<"\n";
myfile<<"Type of Cake "<<numtype<<"\n";
myfile<<"Type of Topping"<<numTopping<<"\n";
myfile<<"The Total price of your cake is"<<newtotalamount<<"\n"<<endl;
myfile<<"Thanks for purchasing \n";

myfile.close();

}
else cout<<"unable to open file";
return 0;

system("PAUSE");
}
Last edited on
It's not clear what you're asking.
http://www.cplusplus.com/forum/beginner/1/#msg6680

Also, please use the format tags to post formatted code.
Can put you code in code tags please? And can you be a bit more specific than "it doesn't work here's my code".
Cheers.

edit: this code is also full of compilation errors. can you sort those out first too?
Last edited on
how to put tags ?
Above your code:

[code]

Below your code:

[/code]
guys my codes is ok just the calculation part i got a bit problem it is showing different output help guys T_T
Last edited on
If you make your code more readable, then more people will read it. So... use code tags!
I feel psychic.
I guess the effective program is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
  double newtotalamount, totalamount, numshape, numtype, numTopping;
  ofstream myfile("Resit.txt");

  newtotalamount = totalamount + (totalamount*0.7);
  myfile<<"\t\tANY CAKE SHOP\n";
  myfile<<"----------------------------------\n";
  myfile<<"Type of Shape"<<numshape<<"\n";
  myfile<<"Type of Cake "<<numtype<<"\n";
  myfile<<"Type of Topping"<<numTopping<<"\n";
  myfile<<"The Total price of your cake is"<<newtotalamount<<"\n"<<endl;
  myfile<<"Thanks for purchasing \n";
  return 0;
}

I guess the question is:
Why does the program write 2.34777e-317 into the Resit.txt?

If so, then the answer is:
Uninitialized variables

Any attempt to refute with the functions asking input from the user is easy to squash with the what happens in Vegas, stays in Vegas stanza.

See arguments by reference from http://www.cplusplus.com/doc/tutorial/functions/
thanks guys for help :)
Topic archived. No new replies allowed.