What should I do when one function finishes another one opens up? - c++

I have a Problem. I'm Trying to make a regular Calculator and Shape's Area and Perimeter finder.It's a combination. I didn't start on my Shape's Area and Perimeter Finder. This is My main.cpp.
#include <iostream>
#include <string>
#include "AAPO.h" // Its a Header File.
using namespace std;
void Calculators_Operation();
int main()
{
string opera;
cout << "Do you want Arithmetic Calculator or Area and Perimeter Calculator"
<< endl;
cin >> opera;
if (opera == "Arithmetic Calculator" or "arithmetic calculator" or "AC")
{
Calculators_Operation();
}
return 0;
}
This is my Operation Chooser.
#include <iostream>
#include <string>
#include "Arithmetic Chooser.h"
using namespace std;
void Calculators_Addition();
void Calculators_Subtraction();
void Calculators_Multiplication();
void Calculators_Division();
void Calculators_Operation()
{
string answera;
cout << "What Operation do you Want?" << endl;
cin >> answera;
if (answera == "Addition" or "addition" or "+");
{
Calculators_Addition();
};
if (answera == "Subtraction" or "subtraction" or "-");
{
Calculators_Subtraction();
};
if (answera == "Multiplication" or "multiplication" or "*" or "x" or "X")
{
Calculators_Multiplication();
};
if (answera == "Division" or "division" or "/")
{
Calculators_Division();
};
return;
}
This is my AAPO.h.
#ifndef AAPO_H_INCLUDED
#define AAPO_H_INCLUDED
void Calculators_Operation();
#endif // AAPO_H_INCLUDED
My Addition.
#include <iostream>
#include <string>
using namespace std;
void calculators_Addition_2();
void calculators_Addition_3();
void calculators_Addition_4();
void calculators_Addition_5();
void Calculators_Addition()
{
//ADDITION COMPLETE
string numberadd;
cout << "How much numbers do you want?" << endl;
cin >> numberadd;
if (numberadd == "2")
{
calculators_Addition_2();
return;
};
if (numberadd == "3")
{
calculators_Addition_3();
return;
};
if (numberadd == "4")
{
calculators_Addition_4();
return;
};
if (numberadd == "5")
{
calculators_Addition_5();
return;
}
}
void calculators_Addition_2()
{
int add11;
int add12;
int sum;
cout << "Enter the first number" << endl;
cin >> add11;
cout << "Enter the second number" << endl;
cin >> add12;
sum = add11 + add12;
cout << "The sum of the numbers are " << sum << endl;
return;
}
void calculators_Addition_3()
{
int add13;
int add23;
int add33;
int sum2;
cout << "Enter the First Number" << endl;
cin >> add13;
cout << "Enter the Second Number" << endl;
cin >> add23;
cout << "Enter the Third Number" << endl;
cin >> add33;
sum2 = add13 + add23 + add33;
cout << "The Sum of the Numbers are " << sum2 << endl;
return;
}
void calculators_Addition_4()
{
int add14;
int add24;
int add34;
int add44;
int sum3;
cout << "Enter the First Number" << endl;
cin >> add14;
cout << "Enter the Second Number" << endl;
cin >> add24;
cout << "Enter the Third Number" << endl;
cin >> add34;
cout << "Enter the Fourth Number" << endl;
cin >> add44;
sum3 = add14 + add24 + add34 + add44;
cout << "The Sum of the Numbers are " << sum3 << endl;
return;
}
void calculators_Addition_5()
{
int a15;
int a25;
int a35;
int a45;
int a55;
int sum4;
cout << "Enter the First Number" << endl;
cin >> a15;
cout << "Enter the Second Number" << endl;
cin >> a25;
cout << "Enter the Third Number" << endl;
cin >> a35;
cout << "Enter the Fourth Number" << endl;
cin >> a45;
cout << "Enter the Fifth Number" << endl;
cin >> a55;
sum4 = a15 + a25 + a35 + a45 + a55;
cout << "The Sum of the Numbers are " << sum4 << endl;
return;
}
My Subtraction.
#include <iostream>
using namespace std;
void Calculators_Subtraction()
{
int subractify;
int subracta;
int differencea;
cout << "Type in the First Number!" << endl;
cin >> subractify;
cout << "Type in the Second Number!" << endl;
cin >> subracta;
differencea = subractify - subracta;
cout << "The Difference is " << differencea << endl;
return;
}
My Multiplication.
#include <iostream>
#include <string>
using namespace std;
void Calculators_Multiplication_2();
void Calculators_Multiplication_3();
void Calculators_Multiplication_4();
void Calculators_Multiplication_5();
void Calculators_Multiplication()
{
string multicipia;
cout << "How much numbers do you want?" << endl;
cin >> multicipia;
if (multicipia == "2" or "Two" or "two")
{
Calculators_Multiplication_2();
};
if (multicipia == "3" or "Three" or "three")
{
Calculators_Multiplication_3();
};
if (multicipia == "4" or "Four" or "four")
{
Calculators_Multiplication_4();
};
if (multicipia == "5" or "Five" or "five")
{
Calculators_Multiplication_5();
};
return;
}
void Calculators_Multiplication_2()
{
int multi2a;
int multi2b;
int product2;
cout << "Type in the First Number." << endl;
cin >> multi2a;
cout << "Type in the Second Number." << endl;
cin >> multi2b;
product2 = multi2a * multi2b;
cout << "The Product is " << product2 << "." << endl;
return;
}
void Calculators_Multiplication_3()
{
int multi3a;
int multi3b;
int multi3c;
int product3;
cout << "Enter the First Number!" << endl;
cin >> multi3a;
cout << "Enter the Second Number!" << endl;
cin >> multi3b;
cout << "Enter the Third Number!" << endl;
cin >> multi3c;
product3 = multi3a * multi3b * multi3c;
cout << "The Product is" << product3 << "." << endl;
return;
}
void Calculators_Multiplication_4()
{
int multi4a;
int multi4b;
int multi4c;
int multi4d;
int product4;
cout << "Enter the First Number!" << endl;
cin >> multi4a;
cout << "Enter the Second Number!" << endl;
cin >> multi4b;
cout << "Enter the Third Number!" << endl;
cin >> multi4c;
cout << "Enter the Fourth Number!" << endl;
cin >> multi4b;
product4 = multi4a * multi4b * multi4c * multi4d;
cout << "The Product of the Numbers are " << product4 << "!" << endl;
return;
}
void Calculators_Multiplication_5()
{
int multi5a;
int multi5b;
int multi5c;
int multi5d;
int multi5e;
int product5;
cout << "Enter the First Number!" << endl;
cin >> multi5a;
cout << "Enter the Second Number!" << endl;
cin >> multi5b;
cout << "Enter the Third Number!" << endl;
cin >> multi5c;
cout << "Enter the Fourth Number!" << endl;
cin >> multi5d;
cout << "Enter the Fifth Number!" << endl;
cin >> multi5e;
product5 = multi5a * multi5b * multi5c * multi5d * multi5e;
cout << "The Product of the Numbers are" << product5 << "!" << endl;
return;
}
My Division.
#include <iostream>
using namespace std;
void Calculators_Division()
{
float divisia;
float divisiab;
float quotient;
cout << "Enter the Divisor" << endl;
cin >> divisia;
cout << "Enter the Dividend" << endl;
cin >> divisiab;
quotient = divisia / divisiab;
cout << "The Quotient of the Numbers are " << quotient << endl;
return;
}
The Problem right now is that when addition finishes , subtraction starts. After Subtraction, Multiplication. After Multiplication, Division. After That the program ends. I'm sorry. Its just that I'm new to programming (Like one month).

There are many things to improve (some of them already mentioned in comments), but exact answer to your question is:
you have semicolon after your if-statement lines in Calculators_Operation() function body, which makes if-statements useless and your "operation" functions are being called every time (what you already noticed).
you use "or" operator in incorrect way, if you use (answera == "addition" or "+"), you basically say: ((answera == "addition) or "+") and that evaluates to true (see here)
EDIT:
Your function Calculators_Operation may be changed to:
void Calculators_Operation()
{
string answera;
cout << "What Operation do you Want?" << endl;
cin >> answera;
if (answera == "Addition" || answera == "addition" || answera == "+")
{
Calculators_Addition();
}
else if (answera == "Subtraction" || answera == "subtraction" || answera == "-")
{
Calculators_Subtraction();
}
else if (answera == "Multiplication" || answera == "multiplication" || answera == "*" || answera == "x" || answera == "X")
{
Calculators_Multiplication();
}
else if (answera == "Division" || answera == "division" || answera == "/")
{
Calculators_Division();
} else {
cout << "Unknown operation entered!" << endl;
}
}
NOTE: all your if statements need to be changed according to this function.
If anything does not work, please either put in comments what exactly does not work or edit your question with new code posting and question.

Related

Part of my code was skipped as part of my if statment

So im trying to make a calculator and i added a part so i can calculate area, first i asked for integer or geometry math, when i choose geometry, it skips my question of you want to calculate volume. But there were no compiler errors. It everything after " else if (choice == "geometry") {" and until the last line. Anyone knows how to fix.
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
string choice;
cout << "choose integer or geometry\n";
cin >> choice;
if (choice == "integer") {
double num1{ 0 };
double num2{ 0 };
cout << "pick a number\n";
cin >> num1;
cout << "pick another number\n";
cin >> num2;
string integerChoice;
cout << "choose addition, subtraction, multipliction, or division\n";
cin >> integerChoice;
if (integerChoice == "addition") {
cout << num1 << " + " << num2 << " is " << num1 + num2
<< '\n';
}
else if (integerChoice == "subtraction") {
cout << num1 << " - " << num2 << " is " << num1 - num2
<< '\n';
}
else if (integerChoice == "multiplication") {
cout << num1 << " * " << num2 << " is " << num1 * num2
<< '\n';
}
else if (integerChoice == "division") {
cout << num1 << " / " << num2 << " is " << num1 / num2
<< '\n';
}//integer is done
}
else if (choice == "geometry") {
string geoChoice1;
cout << "do you want to calculate volume, enter yes or no\n";
cin >> geoChoice1;
if (geoChoice1 == "yes") {
cout << "choose retangular prism(incudes cubes), cone, or cylinder\n";
string volumeChoice;
cin >> volumeChoice;
if (volumeChoice == "rectangular prism") {
double recPrismLength{ 0 };
double recPrismWidth{ 0 };
double recPrismHeight{ 0 };
cout << "Enter the length\n";
cin >> recPrismLength;
cout << "Enter the width\n";
cin >> recPrismWidth;
cout << "Enter the height\n";
cin >> recPrismHeight;
cout << recPrismLength << " * " << recPrismWidth << " * " << recPrismHeight << " is " <<
recPrismLength * recPrismWidth * recPrismHeight << '\n';
}
else if (volumeChoice == "cylinder") {
float cHeight;
float cRadius;
const double pi{ 3.14159265358979323846 };
float cFormula{ pi * pow(2.0, cRadius) * cHeight };
cout << "Enter the height of the cylinder\n";
cin >> cHeight;
cout << "Enter the radius of the cylinder\n";
cin >> cRadius;
cout << cFormula;
}
else if (geoChoice1 == "no") {
Fixed Code:
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
std::string ToLower(std::string str) {
std::transform(str.begin(), str.end(), str.begin(),
[](unsigned char c) { return std::tolower(c); });
}
int main()
{
string choice;
cout << "choose integer or geometry\n";
cin >> choice;
if (choice == "integer") {
double num1{ 0 };
double num2{ 0 };
cout << "pick a number\n";
cin >> num1;
cout << "pick another number\n";
cin >> num2;
string integerChoice;
cout << "choose addition, subtraction, multipliction, or division\n";
cin >> integerChoice;
if (integerChoice == "addition") {
cout << num1 << " + " << num2 << " is " << num1 + num2
<< '\n';
}
else if (integerChoice == "subtraction") {
cout << num1 << " - " << num2 << " is " << num1 - num2
<< '\n';
}
else if (integerChoice == "multiplication") {
cout << num1 << " * " << num2 << " is " << num1 * num2
<< '\n';
}
else if (integerChoice == "division") {
cout << num1 << " / " << num2 << " is " << num1 / num2
<< '\n';
}//integer is done
}
else if (choice == "geometry") {
string geoChoice1;
while (!(geoChoice1 == "yes" || geoChoice1 == "no"))
cout << "do you want to calculate volume, enter yes or no\n";
cin >> geoChoice1;
ToLower(geoChoice1);
if (geoChoice1 == "yes") {
cout << "choose retangular prism(incudes cubes), cone, or cylinder\n";
string volumeChoice;
cin >> volumeChoice;
ToLower(volumeChoice);
if (volumeChoice == "rectangular prism") { //this will never be executed, as the >> operator skips whitespace, and therefore will only read "rectangular"
//I will leave this for you to fix
double recPrismLength{ 0 };
double recPrismWidth{ 0 };
double recPrismHeight{ 0 };
cout << "Enter the length\n";
cin >> recPrismLength;
cout << "Enter the width\n";
cin >> recPrismWidth;
cout << "Enter the height\n";
cin >> recPrismHeight;
cout << recPrismLength << " * " << recPrismWidth << " * " << recPrismHeight << " is " <<
recPrismLength * recPrismWidth * recPrismHeight << '\n';
}
else if (volumeChoice == "cylinder") {
float cHeight;
float cRadius;
const double pi{ 3.14159265358979323846 };
double cFormula{ pi * pow(2.0, cRadius) * cHeight }; //this will always be the same, please note, because cHeight and cRadius are only filled after this function
cout << "Enter the height of the cylinder\n";
cin >> cHeight;
cout << "Enter the radius of the cylinder\n";
cin >> cRadius;
cout << cFormula;
break;
}
}
else if (geoChoice1 == "no") break;
else cout << "Please enter something I understand, either 'yes' or 'no'.\n";
} //this was missing
} //this was missing
Your code did not take into account if the user inputted "Yes" with a capital Y. The code would just conclude that "Yes" would not be equal to "yes". I made a function which converts your input into a lowercase form, then evaluates it, and if it is not "yes" or "no" asks the user to put it again.
There are some other errors which I have put comments on, that you will have to fix.

Undeclared Identifier C2065 "P"

I am a new programming student and this is my first time posting here so I apologize if I did it wrong. I have attached my code below. I am receiving two errors when I try to build my solution. They are : error C2065: 'p': undeclared identifier. I'm confused why p is undeclared but not m or q. I am using visual studio 2017. I understand this may be a simple fix, but I'm new to this and still learning the basics.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
//declare variables//
int kilogram, kilometer, liter;
unsigned char choice = p, m , q;
double pounds, miles, quarts;
//create menu for user//
cout << "Please enter your choice from the menu below\n"
<< "(p)ounds to kilograms\n"
<< "(m)iles to kilometers\n"
<< "(q)uarts to liters\n"
<< "Please enter your conversion choice\n";
cin >> choice;
//validate choice//
if (choice != 'p' && choice != 'm' && choice != 'q')
{
cout << "Invalid Choice\n"
<< "Please enter choice" << endl;
cin >> choice;
}
//Make conversion//
if (choice == p)
{
//Get metric value//
cout << "Please enter the kilogram value\n";
cin >> kilogram;
}
//calculate conversion//
else
{
pounds = kilogram * 2.2046;
cout << kilogram << "kilograms is" << pounds << "Pounds" << endl;
}
//Validate input//
if (kilogram < 1)
{
cout << "Invalid Input" << endl;
cout << "Enter the kilogram value" << endl;
cin >> kilogram;
}
if (choice == m)
{
//Get metric value//
cout << "Please enter the kilometer value\n";
cin >> kilometer;
}
//calculate conversion//
else
{
miles = kilometer * 0.621388;
cout << kilometer << "kilometer is " << miles << "miles" << endl;
}
//Validate Input//
if (kilometer < 1)
{
cout << "Invalid Input" << endl
<< "Enter the kilometer value" << endl;
cin >> kilometer;
}
//Make conversion
if (choice == q)
{
//Get metric value//
cout << "Please enter the liter value\n";
cin >> liter;
}
//Calculate conversion
else
{
quarts = liter * 0.877193;
cout << liter << "liter is" << quarts << "quarts" << endl;
}
//Validate input//
if (liter < 1)
{
cout << "Invalid Input" << endl
<< "Enter the liter value" << endl;
cin >> liter;
}
return 0;
}
because you seperated with comman, so the compiler will consider the code as
unsigned char choice = p;
unsigned char m;
unsigned char q;
So the p is undeclared

Function that Stores the value from each iteration and then totals them

So I am trying to write a program that takes the total cost of a set of books given a certain value and then loop back to the beginning in order to get the total of a new set of books until the user tells it to stop. At the end of the program a total of the total cost of all books will be displayed. I am stuck trying to write this, thanks for any help with this, and sorry for my messy code as I am still learning.
Code Listed Here:
#include <iostream>
using namespace std;
const float kReqNew = 0.90;
const float kReqOld = 0.65;
const float kOptNew = 0.40;
const float kOptOld = 0.20;
class Book {
private:
float singleCost_;
int NeworOld_;
int ReqorOpt_;
int TotalBooksNeeded_;
int BookNumber_;
int NumOnHand_;
int prospectiveEnrole;
double totalCost_;
public:
void buildData();
void determineBooks();
void totalCosts();
void layOut();
void totalCostAdd();
};
void Book::buildData() {
cout << "Please enter: " << endl;
cout << "Book Number:";
cin >> BookNumber_;
cout << "Book Price: ";
cin >> singleCost_;
cout << "How many are in stock: ";
cin >> NumOnHand_;
cout << "Prospective Enrolment: ";
cin >> prospectiveEnrole;
cout << "Required(1), Optional(0)";
cin >> ReqorOpt_;
cout << "New(1), Old(0): ";
cin >> NeworOld_;
}
void Book::determineBooks(){
if(NeworOld_ == 1 && ReqorOpt_ == 1){
TotalBooksNeeded_ = NumOnHand_ * kReqNew;
}
else if(NeworOld_ == 1 && ReqorOpt_ == 0){
TotalBooksNeeded_ = NumOnHand_ * kOptNew;
}
else if(NeworOld_ == 0 && ReqorOpt_ == 1){
TotalBooksNeeded_ = NumOnHand_ * kReqOld;
}
else if(NeworOld_ == 0 && ReqorOpt_ == 0){
TotalBooksNeeded_ = NumOnHand_ * kOptOld;
}
cout << "Total Number of Books Needed: " << "$" << TotalBooksNeeded_ << endl;
}
void Book::totalCosts(){
totalCost_ = TotalBooksNeeded_ * singleCost_;
cout << "The total cost of the books is: " << totalCost_ << endl;
}
void Book::layOut(){
cout << BookNumber_<<endl;
cout << "$" << singleCost_ << endl;
cout << NumOnHand_ << endl;
}
void Book::totalCostAdd(){
double* newTotalCost;
*newTotalCost += totalCost_;
cout << newTotalCost << endl;
}
int main() {
Book books;
int exitNum;
cout << "\t\t\t ****************\n" << "\t\t\t Book Calculator\n" << "\t\t\t ****************\n";
do{
cout << "*******************************************\n";
books.buildData();
cout << "*******************************************\n";
books.layOut();
cout << "*******************************************\n";
books.determineBooks();
books.totalCosts();
cout << "*******************************************\n";
cout << "Would you like to continue: Yes(1), No(0)" << endl;
cin >> exitNum;
cout << "*******************************************\n";
books.totalCostAdd();
} while(exitNum != 0);
}
Thanks again for any help.

Basic Console Calculator (Storing a string in a variable) C++

I'm trying to create a basic console calculator in C++. I'm having a bit of trouble storing a string in a variable from a cin command.
Here is the program for some clarification:
#include <iostream>
using namespace std;
int main()
{
string type_cal;
cout << "Please enter the type of calculation you would like to use: \n";
cout << "1. Addition \n";
cout << "2. Subtraction \n";
cout << "3. Multiplication \n";
cout << "4. Division \n \n";
cin >> type_cal;
if (type_cal = "Addition" or "1")
{
int a;
int b;
int sum;
cout << "Please enter a number to add: \n";
cin >> a;
cout << "Please enter another number: \n";
cin >> b;
sum = a + b;
cout << "The sum of those numbers is: " << sum << endl;
return 0;
}
}
Currently I am in the addition phase since I recently ran into this problem. Quick answers would be appreciated, thank you!
if(type_cal = "Addition" or "1") simply does not make sense.
if(type_cal == "Addition" || type_cal == "1") {
}
Ok I found the problem, or is actually used as || in c++ (thanks aerkenemesis), and = is not the same as == which means equal to (another thanks to Lorehed). Program is working fine now.
For those who are curious, here is the new and revised version of my simple calculator:
#include <iostream>
using namespace std;
float addition();
float subtraction();
float multiplication();
float division();
int main()
{
string type_cal;
cout << "Please enter the type of calculation you would like to use: \n";
cout << "1. Addition " << endl;
cout << "2. Subtraction " << endl;
cout << "3. Multiplication " << endl;
cout << "4. Division" << endl << endl;
cin >> type_cal;
if(type_cal == "Addition")
{
addition();
}
if(type_cal == "Subtraction")
{
subtraction();
}
if(type_cal == "Multiplication")
{
multiplication();
}
if(type_cal == "Division")
{
division();
}
return 0;
}
float addition()
{
float a;
float b;
float sum;
cout << "Please enter a number to add: " << endl;
cin >> a;
cout << "Please enter another number: " << endl;;
cin >> b;
sum = a + b;
cout << "The sum of those numbers is: " << sum << endl;
}
float subtraction()
{
float c;
float d;
float difference;
cout << "Please enter a number to subtract: \n";
cin >> c;
cout << "Please enter another number: \n";
cin >> d;
difference = c - d;
cout << "The difference of those numbers is " << difference << endl;
}
float multiplication()
{
float e;
float f;
float product;
cout << "Please enter a number to multiply: \n";
cin >> e;
cout << "Please enter another number: \n";
cin >> f;
product = e * f;
cout << "The product of those numbers is " << product << endl;
}
float division()
{
float g;
float h;
float quotient;
cout << "Please enter a number to divide: \n";
cin >> g;
cout << "Please enter another number: \n";
cin >> h;
quotient = g / h;
cout << "The quotient of those numbers is " << quotient << endl;
}

C++ my program reads backspace as a character

I am working with a c++ program, but I am stuck with annoying bug. The bug is that when i type the password, it counts backspace as a character so can I fix it? Here is the code.
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
string password, username, lon, nu, np;
char c;
int StarNum = 0, humanproof;
cout << "Do you wanna create a user or login?";
cout << "\nLogin" << endl;
cout << "New" << endl;
cin >> lon;
if(lon=="login"){
goto login;
}
if(lon=="new"){
goto newa;
}
login:
cout << "Username: ";
cin >> username;
lol:
cout << "Password: ";
while (c != 13)
{
c = (char)getch();
if(c == 13) break;
StarNum++;
password += c;
cout << "*";
if (c == 127 || c == 8){
//go here to fix the problem
}
password = "";
goto lol;
}
}
if(username == "user" && password == "pass" || username == nu && password == np){
cout << "\nYou are logged in.";
goto options;
} else {
cout << "\nusername or password is wrong" << endl;
return 0;
}
return 0;
newa:
cout << "Username:";
cin >> nu;
cout << "password:";
cin >> np;
cout << "Type the number fourhoundred and twentie three too proof you are a human: ";
cin >> humanproof;
if(humanproof == 423){
cout << "The username is " << nu << endl;
for(int no = 0; no <= 100; no++){
cout << endl;
}
goto login;
return 0;
}
if(humanproof!=423){
cout << "wrong answer!";
return 0;
}
options:
int op;
cout << "\nwhat do you want to do?" << endl;
cout << "1. Calculator" << endl;
cout << "2. About"<< endl;
cout << "3. Just for fun" << endl;
cout << "4. Exit" << endl;
cin >> op;
if(op==1){
goto calculator;
}
if(op==2){
goto info;
}
if(op==3){
goto fun;
}
if(op==4){
return 0;
}
else{
cout << "you entered a invalid number. " << endl;
return 0;
}
calculator:
double n1, n2, sum;
int opa;
cout << "Choose a operation" << endl;
cout << "1. Addition/+" << endl;
cout << "2. Subscraction/-" << endl;
cout << "3. Multiplication/x" << endl;
cout << "4. Divsion/ /" << endl;
cin >> opa;
if(opa == 1){
cout << "enter number 1" << endl;
cin >> n1;
cout << "enter number 2" << endl;
cin >> n2;
sum = n1 + n2;
cout << "the sum is " << sum;
return 0;
}
if(opa == 2){
cout << "enter number 1" << endl;
cin >> n1;
cout << "enter number 2" << endl;
cin >> n2;
sum = n1 - n2;
cout << "the sum is " << sum;
return 0;
}
if(opa == 3){
cout << "enter number 1" << endl;
cin >> n1;
cout << "enter number 2" << endl;
cin >> n2;
sum = n1 * n2;
cout << "the sum is " << sum;
return 0;
}
if(opa == 4){
cout << "enter number 1" << endl;
cin >> n1;
cout << "enter number 2" << endl;
cin >> n2;
sum = n1 / n2;
cout << "the sum is " << sum;
return 0;
}
if(opa > 4){
cout << "You entered a invalid number";
goto calculator;
}
info:
cout << "Created by Bergur 2013";
return 0;
fun:
cout << "You want an eyepad(ipad)?";
}
Your code already checks:
while (c != 13)
And prevent newline from being handled, do similar to what you need with the backspace character, whose number is 8
To fix your issue, before:
StarNum++;
Add:
if (c == 8 && StarNum > 0) {
StarNum--;
if (password.size () > 0)
password.resize (password.size () - 1);
continue;
}
Please format your code. Also, try to provide a minimal code which reproduce the problem, not the whole code.
Unrelated to your problem
Try not to use goto.
Do not use ASCII values, but use the char literals instead, i.e. use '\n' instead of 13.
Also, you can simply add an iother condition inside your while:
while (c != '\n' && c != ' ')