I decided to do an overhaul of the code, and this is what I came up with:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
using namespace std;
const string UNIVERSITY = "placeholder"; //Define a line of University Name
const string LOCATION = "placeholder "; //Define a line of location
const string NAME = "placeholder"; //Define a line of first and last name
const string DEPARTMENT = "placeholder"; //Define a line of department
int main(int argc, char **argv)
{
int choice;
cout << fixed << showpoint << setprecision(2) << endl;
cout << "This program can calculate volume of a cone, "
<< "or print a name card." << endl;
cout << "Main Menu: " <<endl;
cout << "1: Print a name card." << endl;
cout << "2: Calculate the volume of a cone." << endl;
cout << "0: Exit the Program" << endl;
cin >> choice;
cout << endl;
while (choice != 0)
{
switch (choice)
{
case 1:
stringstream stream;
string s;
for(int i=0; i<60; i++)
stream<<"*";
stream<<"\n";
stream<<"*"<<UNIVERSITY<<" "<<LOCATION<<"*\n*\n*\n";
stream<<NAME<<"*\n*\n";
stream<<DEPARTMENT<<"*\n*\n";
for(int i=0; i<60; i++)
stream<<"*";
stream<<"\n";
s = stream.str();
cout<<s;
system ("PAUSE");
break;
case 2:
float r, h, v;
float pi = 3.14159;
r = 5.8;
h = 6.3;
cout << "What is the Radius?";
cin >> r;
cout << "What is the Height?";
cin >> h;
v = (1.0/3.0) * pi * (r*r) * h;
cout << "The volume of the cone is\n\n " << v << "\n";
system ("PAUSE");
break;
default:
cout << "Invalid choice!" << endl;
}
cout << "Main Menu: " <<endl;
cout << "1: Print a name card" << endl;
cout << "2: Calculate the volume of a cone." << endl;
cout << "0: Exit the program." << endl;
cin >> choice;
cout << endl;
}
return 0;
}
|
There only seem to be minor errors throughout, but I don't quite understand what the compiler's saying.
In function `int main(int, char**)':
56 jump to case label
37 crosses initialization of `std::string s'
36 crosses initialization of `std::stringstream stream'
74 jump to case label
58 crosses initialization of `float pi'
37 crosses initialization of `std::string s'
36 crosses initialization of `std::stringstream stream'
56 [Warning] destructor needed for `s'
56 [Warning] where case label appears here
56 [Warning] (enclose actions of previous case statements requiring destructors in their own scope.)
74 [Warning] destructor needed for `s'
74 [Warning] where case label appears here
These are all the errors it has. As usual, any help would be greatly appreciated.