I have a few questions about random things about programming and any help would be appreciated.
First off, I'm a beginner as you can probably tell by my code and I would like to know how I could make it so my calculator can have any number of inputs to be added, subtracted etc instead of just having 2 and not having to put in a bunch of extra variables that might not even be needed. Also any tips on improving the look of my code would help me.
I'm using visual C++ 2008 to practice coding and I'm wondering how would I be able to transfer my calculator program to another computer. Also I have Windows Vista 64-bit if that matters.
Pretty soon I'm going to be taking a class on C++ as part of my technical degree; after finishing the degree I'll be transferring to a four year college. I'm wondering what to expect from the class because the course description online just says, "you will learn C++".
One thing that I find interesting is AI and if you can do any of that in C++ and if so where could i learn about it?
Code for my calculator program, which works fine by the way:
Code:
#include <iostream>
using namespace std;
int mult(int a, int b);
int divide(int a, int b);
int add(int a, int b);
int subt(int a, int b);
int main()
{
int a, b, x;
char cChar, yesno;
cout<< "Welcome to my amazing calculator program.\n";
redo: //goto redo label
cout<<"1.Multiply \n";
cout<<"2.Divide \n";
cout<<"3.Add \n";
cout<<"4.Subtract \n";
cout<<"Enter the number of your selection: \n\n";
cin>> x;
switch (x){
case 1:
cout<<"Type two whole numbers you want MULTIPLIED \n"; // MULTIPLY
cin>>a >> b;
cout<<"Your answer is: ";
cout<< mult(a,b)<<endl;
cin.get(cChar);
cout<<"\n";
cout<<"Again? (y/n)"<<endl;
cin>>yesno;
if(yesno=='y'){
cout<<"\n";
goto redo;
}
else break;
case 2:
redo_div: //goto redo_div label
cout<<"Type two whole numbers you want DIVIDED \n"; // DIVIDE
cin>>a >> b;
if(b==0){
cout<<"DONT DO THAT :)"<<endl; //Makes sure cannot divide by zero
goto redo_div;
}
cout<<"Your answer is: ";
cout<< divide(a,b)<<endl;
cin.get(cChar);
cout<<"\n";
cout<<"Again? (y/n)"<<endl;
cin>>yesno;
if(yesno=='y'){
cout<<"\n";
goto redo;
}
else break;
case 3:
cout<<"Type two whole numbers you want ADDED \n"; // ADD
cin>>a >> b;
cout<<"Your answer is: ";
cout<< add(a,b)<<endl;
cin.get(cChar);
cout<<"\n";
cout<<"Again? (y/n)"<<endl;
cin>>yesno;
if(yesno=='y'){
cout<<"\n";
goto redo;
}
else break;
case 4:
cout<<"Type two whole numbers you want SUBTRACTED \n"; // SUBTRACT
cin>>a >> b;
cout<<"Your answer is: ";
cout<< subt(a,b)<<endl;
cin.get(cChar);
cout<<"\n";
cout<<"Again? (y/n)"<<endl;
cin>>yesno;
if(yesno=='y'){
cout<<"\n";
goto redo;
}
else break;
default: // ERROR
cout<<"You did something wrong...";
cin.get(cChar);
cout<<"\n";
cout<<"Again? (y/n)"<<endl;
cin>>yesno;
if(yesno=='y'){
cout<<"\n";
goto redo;
}
else break;
}
return 0;
}
int mult(int a, int b)
{
return a*b;
}
int divide(int a, int b)
{
return a/b;
}
int add(int a, int b)
{
return a+b;
}
int subt(int a, int b)
{
return a-b;
}