0
jimblumberg's Avatar
Ambitious contributor
Please re-post the entire updated program.

Jim
0
Shihonoryu's Avatar, Join Date: Oct 2010
Go4Expert Member
HTML Code:
#include <cstdlib>
#include <iostream>
#include <string>
#include "AllMath_H.h"


int main()
{
	int looping = 0;
	using namespace std;
    string choice1;
    while (looping == 0)
{
    system("cls");
    cout << "====================================================" << endl;
    cout << "====                Main Menu                   ====" << endl;
    cout << "====================================================" << endl;
    cout << "====================================================" << endl;
    cout << "====  Please enter what calculation you want.   ====" << endl;
    cout << "====        A. Find the area of a shape.        ====" << endl;
    cout << "====        B. basic calculation.               ====" << endl;
    cout << "====================================================" << endl;
    cout << "====================================================" << endl;
    cout << "Please Choose: ";
    cin >> choice1;
    cout << " ";
	
	
    if (choice1 == "A")
    
{
    system("cls");
    cout << "Please enter what shape you want to find the area of(circle, triangle, or square. CAP SENSITIVE)" << endl;
    string choice;
    cin >> choice;

if ( choice == "circle" )//CIRCLE CHOICE

	{
         system("cls");
         cout << "Please enter the radius of your circle" << endl;
         int x;
         cin >> x;
         findAreaOfCircle(x);
         cout << "Do you want to use the calculator again?" << endl;
         string awnser;
         cin >> awnser;

         if (awnser == "no")
		{
         cout << "goodbye!" << endl;
         looping = 1;
		}

         
           
	}

else if ( choice == "square")//square choice

	{
     system("cls");
     int L;
     int H;
     cout << "Please enter the length of your square" << endl;
     cin >> L;
     cout << "Please enter the heigth of your square" << endl;
     cin >> H;
     findAreaOfSquare(L,H);
              cout << "Do you want to use the calculator again?" << endl;
         string awnser;
         cin >> awnser;

         if (awnser == "no")
		{
         cout << "goodbye!" << endl;
         looping = 1;
		}

	}

	else if ( choice == "triangle" )//Triangle choice

	{
     system("cls");
     int H;
     int B;
     cout << "Please enter the base of your triangle" << endl;
     cin >> B; 
     cout << "Please enter the heigth of your triange" << endl;
     cin >> H;
     FindAreaOfTriangle(H,B);
     
         cout << "Do you want to use the calculator again?" << endl;
         string awnser;
         cin >> awnser;

         if (awnser == "no")
		 {
         cout << "goodbye!" << endl;
         looping = 1;
		 }


	else 
	{
		cout << "Invalid choice\n";
		cin.get();
	}

	}
    
	




if (choice1 == "B")
{
	 system("cls");
     cout << "Please choose what operation you wish to do." << endl;
     string choice;
     cin >> choice;
     if (choice == "add")
     {
         int a;
         int b;
         system("cls");
         cout << "Please enter a number" << endl;
         cin >> a;
         cout << "Please enter another number" << endl;
         cin >> b;
         add(a,b);
         cout << "Do you want to use the calculator again?" << endl;
         string awnser;
         cin >> awnser;

         if (awnser == "no")
		{
         cout << "goodbye!" << endl;
         looping = 1;
		}


     }


	 else if(choice == "subtract")
	 {
		 int a;
		 int b;
		 system("cls");
		 cout << "Whats the minuend?" << endl;
		 cin >> a;
		 cout << "whats the subtrahend?" << endl;
		 cin >> b;
		 subtract(a,b);
         cout << "Do you want to use the calculator again?" << endl;
         string awnser;
         cin >> awnser;

         if (awnser == "no")
			{
				cout << "goodbye!" << endl;
				looping = 1;
			}


         

	}
}
}
}




return 0;
}


when incorrect input happends, it doesnt go into that last else in the Area finding part of the code
0
jimblumberg's Avatar
Ambitious contributor
If your indentation was consistent it would be easier to see why you don't enter the else.
Code:
#include <cstdlib>
#include <iostream>
#include <string>
#include "AllMath_H.h"


int main()
{
    int looping = 0;
    using namespace std;
    string choice1;
    while (looping == 0)
    {
        system("cls");
        cout << "====================================================" << endl;
        cout << "====                Main Menu                   ====" << endl;
        cout << "====================================================" << endl;
        cout << "====================================================" << endl;
        cout << "====  Please enter what calculation you want.   ====" << endl;
        cout << "====        A. Find the area of a shape.        ====" << endl;
        cout << "====        B. basic calculation.               ====" << endl;
        cout << "====================================================" << endl;
        cout << "====================================================" << endl;
        cout << "Please Choose: ";
        cin >> choice1;
        cout << " ";


        if (choice1 == "A")
        {
            system("cls");
            cout << "Please enter what shape you want to find the area of(circle, triangle, or square. CAP SENSITIVE)" << endl;
            string choice;
            cin >> choice;

            if ( choice == "circle" )//CIRCLE CHOICE
            {
                system("cls");
                cout << "Please enter the radius of your circle" << endl;
                int x;
                cin >> x;
                findAreaOfCircle(x);
                cout << "Do you want to use the calculator again?" << endl;
                string awnser;
                cin >> awnser;

                if (awnser == "no")
                {
                    cout << "goodbye!" << endl;
                    looping = 1;
                }
            }
            else if ( choice == "square")//square choice
            {
                system("cls");
                int L;
                int H;
                cout << "Please enter the length of your square" << endl;
                cin >> L;
                cout << "Please enter the heigth of your square" << endl;
                cin >> H;
                findAreaOfSquare(L,H);
                cout << "Do you want to use the calculator again?" << endl;
                string awnser;
                cin >> awnser;

                if (awnser == "no")
                {
                    cout << "goodbye!" << endl;
                    looping = 1;
                }
            }
            else if ( choice == "triangle" )//Triangle choice
            {
                system("cls");
                int H;
                int B;
                cout << "Please enter the base of your triangle" << endl;
                cin >> B;
                cout << "Please enter the heigth of your triange" << endl;
                cin >> H;
                FindAreaOfTriangle(H,B);

                cout << "Do you want to use the calculator again?" << endl;
                string awnser;
                cin >> awnser;

                if (awnser == "no")
                {
                    cout << "goodbye!" << endl;
                    looping = 1;
                }
                else   /// Is this the else you are talking about??????????????????????
                {
                    cout << "Invalid choice\n";
                    cin.get();
                }

            }
            
            if (choice1 == "B")
            {
                system("cls");
                cout << "Please choose what operation you wish to do." << endl;
                string choice;
                cin >> choice;
                if (choice == "add")
                {
                    int a;
                    int b;
                    system("cls");
                    cout << "Please enter a number" << endl;
                    cin >> a;
                    cout << "Please enter another number" << endl;
                    cin >> b;
                    add(a,b);
                    cout << "Do you want to use the calculator again?" << endl;
                    string awnser;
                    cin >> awnser;

                    if (awnser == "no")
                    {
                        cout << "goodbye!" << endl;
                        looping = 1;
                    }
                }
                else if(choice == "subtract")
                {
                    int a;
                    int b;
                    system("cls");
                    cout << "Whats the minuend?" << endl;
                    cin >> a;
                    cout << "whats the subtrahend?" << endl;
                    cin >> b;
                    subtract(a,b);
                    cout << "Do you want to use the calculator again?" << endl;
                    string awnser;
                    cin >> awnser;

                    if (awnser == "no")
                    {
                        cout << "goodbye!" << endl;
                        looping = 1;
                    }
                }
            }
        }
    }
   return 0;
}
If the else you are talking about is the one marked, when will it be entered????

Jim
0
Shihonoryu's Avatar, Join Date: Oct 2010
Go4Expert Member
Oh i see now! haha its in the wronf place, it will *never* be entered! haha
0
Shihonoryu's Avatar, Join Date: Oct 2010
Go4Expert Member
See but theres still a problem, its entering the Else that iwant it too when i have wrong input, but i have cin.get(); there, but it seems to skip over cin.get(); it works if i put regular cin there, but i just want the user to have to press enter on teh keyboard.
0
jimblumberg's Avatar
Ambitious contributor
Ok, but my mind reading software is back--ordered..

Please post some code with the problem highlighted.

Jim
0
Shihonoryu's Avatar, Join Date: Oct 2010
Go4Expert Member
Code:
#include <cstdlib>
#include <iostream>
#include <string>
#include "AllMath_H.h"


int main()
{
	int looping = 0;
	using namespace std;
    string choice1;
    while (looping == 0)
{
    system("cls");
    cout << "====================================================" << endl;
    cout << "====                Main Menu                   ====" << endl;
    cout << "====================================================" << endl;
    cout << "====================================================" << endl;
    cout << "====  Please enter what calculation you want.   ====" << endl;
    cout << "====        A. Find the area of a shape.        ====" << endl;
    cout << "====        B. basic calculation.               ====" << endl;
    cout << "====================================================" << endl;
    cout << "====================================================" << endl;
    cout << "Please Choose: ";
    cin >> choice1;
    cout << " ";
	
	
    if (choice1 == "A")
    
{
    system("cls");
    cout << "Please enter what shape you want to find the area of(circle, triangle, or square. CAP SENSITIVE)" << endl;
    string choice;
    cin >> choice;

if ( choice == "circle" )//CIRCLE CHOICE

	{
         system("cls");
         cout << "Please enter the radius of your circle" << endl;
         int x;
         cin >> x;
         findAreaOfCircle(x);
         cout << "Do you want to use the calculator again?" << endl;
         string awnser;
         cin >> awnser;

         if (awnser == "no")
		{
         cout << "goodbye!" << endl;
         looping = 1;
		}

         
           
	}

else if ( choice == "square")//square choice

	{
     system("cls");
     int L;
     int H;
     cout << "Please enter the length of your square" << endl;
     cin >> L;
     cout << "Please enter the heigth of your square" << endl;
     cin >> H;
     findAreaOfSquare(L,H);
              cout << "Do you want to use the calculator again?" << endl;
         string awnser;
         cin >> awnser;

         if (awnser == "no")
		{
         cout << "goodbye!" << endl;
         looping = 1;
		}

	}

	else if ( choice == "triangle" )//Triangle choice

	{
     system("cls");
     int H;
     int B;
     cout << "Please enter the base of your triangle" << endl;
     cin >> B; 
     cout << "Please enter the heigth of your triange" << endl;
     cin >> H;
     FindAreaOfTriangle(H,B);
     
         cout << "Do you want to use the calculator again?" << endl;
         string awnser;
         cin >> awnser;

         if (awnser == "no")
		 {
         cout << "goodbye!" << endl;
         looping = 1;
		 }


	

	}

else //  a***************************************    THIS IS THE ELSE IM TALKING ABOUT  ********************** //
	{
		cout << "Invalid choice\n" << endl;
		cout << "Press Enter to continue" << endl;
		
		
	}
    
	


	

if (choice1 == "B")
{
	 system("cls");
     cout << "Please choose what operation you wish to do." << endl;
     string choice;
     cin >> choice;
     if (choice == "add")
     {
         int a;
         int b;
         system("cls");
         cout << "Please enter a number" << endl;
         cin >> a;
         cout << "Please enter another number" << endl;
         cin >> b;
     
		 add(a,b);
         cout << "Do you want to use the calculator again?" << endl;
         string awnser;
         cin >> awnser;

         if (awnser == "no")
		{
         cout << "goodbye!" << endl;
         looping = 1;
		}


     }


	 else if(choice == "subtract")
	 {
		 int a;
		 int b;
		 system("cls");
		 cout << "Whats the minuend?" << endl;
		 cin >> a;
		 cout << "whats the subtrahend?" << endl;
		 cin >> b;
		 subtract(a,b);
         cout << "Do you want to use the calculator again?" << endl;
         string awnser;
         cin >> awnser;

         if (awnser == "no")
			{
				cout << "goodbye!" << endl;
				looping = 1;
			}


         

	}
}
}
}

return 0;
}]


Thats the else...
0
jimblumberg's Avatar
Ambitious contributor
The problem is probably a newline character has been left in the input buffer. The following code should solve the problem.

Code:
   cin.ignore(100, "\n");
   cin.get();
The cin.ignore() will discard up to 100 characters or new line.

Jim
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
There's nothing wrong with system("cls"); to clear the screen in Windows. This is the correct command. But this line of code cannot possibly throw the error "error C3861: 'clrscr': identifier not found".

fatal error C1075: end of file found before the left brace '{'
I'm not surprised. You need to learn about good formatting. Visual Studio does it for you automatically; just press return at the end of a line and it will drop the cursor exactly where you need to be (with very few exceptions). I'm not going to reformat your entire application for you, but this:
Code:
else if ( choice == "triangle" )//Triangle choice

{
     system("cls");
     int H;
     int B;
     cout << "Please enter the base of your triangle" << endl;
     cin >> B; 
     cout << "Please enter the heigth of your triange" << endl;
     cin >> H;
     FindAreaOfTriangle(H,B);
     
         cout << "Do you want to use the calculator again?" << endl;
         string awnser;
         cin >> awnser;

         if (awnser == "no")
{
         cout << "goodbye!" << endl;
         looping = 1;
}
}
should be:
Code:
	else if ( choice == "triangle" )//Triangle choice
	{
		system("cls");
		int H;
		int B;
		cout << "Please enter the base of your triangle" << endl;
		cin >> B; 
		cout << "Please enter the heigth of your triange" << endl;
		cin >> H;
		FindAreaOfTriangle(H,B);

		cout << "Do you want to use the calculator again?" << endl;
		string awnser;
		cin >> awnser;

		if (awnser == "no")
		{
			cout << "goodbye!" << endl;
			looping = 1;
		}
	}
Your indentation is all over the place so it's not in the least bit surprising you haven't matched your braces correctly.

"im using Visual C++ 2008. how do i run a program? i cant find a "run" or anything anywhere"

So do I. Debug -> Start without Debugging. Shortcut on my PC is Ctrl-F5.


"This isnt a error but my Else statement to stop the user from entering incorrect input isnt working"

I'm not surprised. Just look at the indentation. It's all over the place so there's no surprise you haven't got a clue where you are in the code. Indent correctly and this will almost certainly solve 90% of your problems.


OK, against my better judgment here we go with a correctly formatted program. I haven't attempted to solve the problems. Just look where the final return 0; is.
Code:
int test32()
{
	int looping = 0;
	using namespace std;
	string choice1;
	while (looping == 0)
	{
		system("cls");
		cout << "====================================================" << endl;
		cout << "====                Main Menu                   ====" << endl;
		cout << "====================================================" << endl;
		cout << "====================================================" << endl;
		cout << "====  Please enter what calculation you want.   ====" << endl;
		cout << "==== A. Find the area of a shape.               ====" << endl;
		cout << "==== B. basic calculation.(not implemented yet) ====" << endl;
		cout << "====================================================" << endl;
		cout << "====================================================" << endl;
		cout << "Please Choose: ";
		cin >> choice1;
		cout << " ";
		if (choice1 == "A")
		{
			system("cls");
			cout << "Please enter what shape you want to find the area of(circle, triangle, or square. CAP SENSITIVE)" << endl;
			string choice;
			cin >> choice;

			if ( choice == "circle" )//CIRCLE CHOICE
			{
				system("cls");
				cout << "Please enter the radius of your circle" << endl;
				int x;
				cin >> x;
				findAreaOfCircle(x);
				cout << "Do you want to use the calculator again?" << endl;
				string awnser;
				cin >> awnser;

				if (awnser == "no")
				{
					cout << "goodbye!" << endl;
					looping = 1;
				}
			}
			else if ( choice == "square")//square choice
			{
				system("cls");
				int L;
				int H;
				cout << "Please enter the length of your square" << endl;
				cin >> L;
				cout << "Please enter the heigth of your square" << endl;
				cin >> H;
				findAreaOfSquare(L,H);
				cout << "Do you want to use the calculator again?" << endl;
				string awnser;
				cin >> awnser;

				if (awnser == "no")
				{
					cout << "goodbye!" << endl;
					looping = 1;
				}
			}
			else if ( choice == "triangle" )//Triangle choice
			{
				system("cls");
				int H;
				int B;
				cout << "Please enter the base of your triangle" << endl;
				cin >> B; 
				cout << "Please enter the heigth of your triange" << endl;
				cin >> H;
				FindAreaOfTriangle(H,B);

				cout << "Do you want to use the calculator again?" << endl;
				string awnser;
				cin >> awnser;

				if (awnser == "no")
				{
					cout << "goodbye!" << endl;
					looping = 1;
				}
			}
		}
		else if (choice1 == "B")
		{
			cout << "Please choose what operation you wish to do." << endl;
			string choice;
			cin >> choice;
			if (choice == "add")
			{
				int a;
				int b;
				system("cls");
				cout << "Please enter a number" << endl;
				cin >> a;
				cout << "Please enter another number" << endl;
				cin >> b;
				add(a,b);
				cout << "Do you want to use the calculator again?" << endl;
				string awnser;
				cin >> awnser;

				if (awnser == "no")
				{
					cout << "goodbye!" << endl;
					looping = 1;
				}
			}
			else if(choice == "subtract")
			{
				int a;
				int b;
				system("cls");
				cout << "Whats the minuend?" << endl;
				cin >> a;
				cout << "whats the subtrahend?" << endl;
				cin >> b;
				subtract(a,b);
				cout << "Do you want to use the calculator again?" << endl;
				string awnser;
				cin >> awnser;

				if (awnser == "no")
				{
					cout << "goodbye!" << endl;
					looping = 1;
				}
				return 0;
			}

Last edited by xpi0t0s; 27Oct2010 at 14:11..