So I have to create an AI program than interacts with the user and responds based on the user input. I'm not very experienced, and this has already took hours lmao, I've looked online but I figured I'd actually post my code and try get some help/advice.
Basically the AI helps with maths, I have the program introducing itself and asking what it wants help with but when I enter Addition, Subtraction etc it just responds with numbers when it should respond with "Great, I'll help you with Addition!/(whatever user input)"
Screenshot of first running program: http://prntscr.com/elw7b4 Screenshot after entering what user needs help with: http://prntscr.com/elw7ky (Obviously it's a bit all over the place at the moment, I did the calculator before anything else hence why it's giving additional results.
The calculator was working before entering the following code: (As you can see http:// prntscr.com /elwavs only two links cos haven't got more than 10 rep)
void Inpsum()
{
cout << "Hello, my name is Eva! I am able to help you with basic Maths! How may I be of Assistance today?" << endl;
float inpsum;
cin >> inpsum;
cout << "Great!, I will help you with " << (inpsum) << endl;
}
but entering the above code broke the calculator.
here is the full code:
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <iomanip>
using namespace std;
//user inputs what he needs help with/program output
void Inpsum()
{
cout << "Hello, my name is Eva! I am able to help you with basic Maths! How may I be of Assistance today?" << endl;
cin >> inpsum;
cout << "Great!, I will help you with " << (inpsum) << endl;
}
//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 ;
}
Basically - I've set the calculator up, and it was working. But upon trying to implement input and output between the user and the program I'm going wrong and have broken everything. Instead of the program saying "Great I'll help you with Addition", it says "Great, I'll help you with -134567432"
I'm not asking for anyone to do it for me, rather point me in the right direction so I can actually know what to do in the future.
Notice you define inpsum
using float inpsum;
, but what you are trying to store is string, or words. They are not compatible. You can learn something more about data types and strings in C++.