dimanche 19 mars 2017

Using if/else if in my calculator program

I'm working on a project by where I have to create a simple program that works based of the user input. I've gone with a basic calculator but I'm having trouble getting my if/else if statements to work. Basically, if the user types in "Addition", I want the program to say "...I will help you with addition!", and so on for whether the user says "Subtraction", "Division", and "Multiplication". I then want it to take it to the part of the program that does the calculations(calculator currently works - but this isn't the bit im stuck on [yet] lmao and so you don't have to help with this bit). I just want the if else if statements to work.

I'm new to this and so this has already taken me hours upon hours, not looking for you to do it for me but to point out my erorrs and advise so that I can learn from it will be great.

TIA.

#include <iostream>
#include <cstdlib>
#include <cmath>
#include <iomanip>

using namespace std;

//user inputs what he needs help with/program output
char Inpsum()
{
cout << "Hello, my name is Eva! I am able to help you with basic Maths! How may I be of assistance today?" << endl;
char inpsum[20];
cin >> inpsum;
char output;
if (inpsum == "adding") { //if user enters "adding"


    cout << "Great!, I will help you with " << (inpsum) << endl; //then output = "...i will help with adding"


else if (inpsum == "subtraction"); //otherwise, if user enters "subtraction"

    cout << "Great!, I will help you with " << (inpsum) << endl; //then output = "...i will help with subtraction"


else if (inpsum == "division"); //if user enters "division" 

    cout << "Great!, I will help you with " << (inpsum) << endl; ////then output = "...i will help with division"

else if (impsum == "multiplication"); //if user enters "muliplication"

cout << "Great, I will help you with " << (inpsum) << endl; ////then output = "...i will help with multiplication"

return 0; 

}

//addition function
void Add() {
float add1, add2;
cout << "Please enter two values you want added together" << endl;
cin >> add1;
cin >> add2;
cout << "The answer is: " << (add1 + add2) << endl;
}

//subtraction function
void Subt() {
float subt1, subt2;
cout << "Please enter two values you want subtracted" << endl;
cin >> subt1;
cin >> subt2;
cout << "The answer is: " << (subt1 - subt2) << endl;
}

//division function
void Div()
{
    float div1, div2;
    cout << "Please enter two values you want divided" << endl;
    cin >> div1;
    cin >> div2;
    cout << "The answer is: " << (div1 / div2) << endl;
}

//multiplication function
void Mult() {
float mult1, mult2;
cout << "Please enter two values you want multiplacted" << endl;
cin >> mult1;
cin >> mult2;
cout << "The answer is: " << (mult1 * mult2) << endl;
}



int main()
{
Inpsum(); //user inputs what they want help with
Add();
Subt();
Div();
Mult();

    return 0 ; 
}

Aucun commentaire:

Enregistrer un commentaire