I have these errors: Code: \Calculator.cpp(33) : warning C4627: '#include <cstdlib>': skipped when looking for precompiled header use 1> Add directive to 'stdafx.h' or rebuild precompiled header 1>.\Calculator.cpp(34) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use 1> Add directive to 'stdafx.h' or rebuild precompiled header 1>.\Calculator.cpp(35) : warning C4627: '#include <string>': skipped when looking for precompiled header use 1> Add directive to 'stdafx.h' or rebuild precompiled header 1>.\Calculator.cpp(36) : warning C4627: '#include "AllMath_H.h"': skipped when looking for precompiled header use 1> Add directive to 'stdafx.h' or rebuild precompiled header 1>.\Calculator.cpp(172) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? 1>AllMath.cpp 1>.\AllMath.cpp(3) : warning C4627: '#include "allmath_h.h"': skipped when looking for precompiled header use 1> Add directive to 'stdafx.h' or rebuild precompiled header 1>.\AllMath.cpp(4) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use 1> Add directive to 'stdafx.h' or rebuild precompiled header from this code.... Code: #include <cstdlib> #include <iostream> #include <string> #include "AllMath_H.h" yeah i dont understand it at all
You need to either turn off pre-compiled headers or add Code: #include <stdafx.h> and add the headers to stdafx.h Jim
Alright, i foxed all that. now i have another error. i have this code: Code: system("cls"); and get this error: [COD1>c:\users\dad\documents\visual studio 2008\projects\calculator1\calculator1\calculator1.cpp(176) : error C3861: 'clrscr': identifier not foundE][/CODE] and what im making a is a calculator, that calculates The area of a any 3 shapes, and also does basic operations
Now i have One more error and my code "should be" completely debugged.(Till i add something else :P) Code: HTML: //Includes: #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.(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; } Now thats the Entire Main() function the error is as follows: 1>c:\users\dad\documents\visual studio 2008\projects\calculator1\calculator1\calculator1.cpp(201) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\dad\documents\visual studio 2008\projects\calculator1\calculator1\calculator1.cpp(141)' was matched Now i have no idea how to fix this.
system("cls") is operating system dependent. If you are on Windows it may need to be system("clear"); For your second question your braces do not match. You are missing at least 2. Using consistent indentation will help find these errors. Jim
Hah! your right, i was missing Braces, 3 of them So one question, im using Visual C++ 2008. how do i run a program? i cant find a "run" or anything anywhere, it runs the program when i debug, is that the only way?
I am not sure how to run a program from Visual C++. But you can run a program from the command line. Sorry but I haven't used Windows in many years so I can't supply too many answers for that operating system. Jim
This isnt a error but my Else statement to stop the user from entering incorrect input isnt working: HTML: 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"; } } When you enter something wrong, the loop just restarts at the beginning
What i want to happen is for it to go back to cout << "Please enter what shape you want to find the area of(circle, triangle, or square. CAP SENSITIVE)" << endl;
HTML: #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
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 [COLOR="Red"]/// Is this the else you are talking about?????????????????????[/COLOR]? { 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
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.
Ok, but my mind reading software is back--ordered.. Please post some code with the problem highlighted. Jim
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...
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
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; }