Hi, im very new to c++ and am trying to learn by actually studying code etc.
I took this simple code from this tutorial website.
now, i know what nearly all of this is doing. except why the intergers are there at the start.Code:#include <iostream> int multiply(int x, int y) { return x*y; } int divide(int x, int y) { return x/y;} int add(int x, int y) { return x+y; } int subtract(int x, int y) { return x-y;} using namespace std; int main(){ char op='c'; int x, y; while(op!='e') { cout<<"What operation would you like to perform: add(+),subtract(-), divide(/),multiply(*), [e]xit?"; cin>>op; switch(op) { case '+': cin>>x; cin>>y; cout<<x<<"+"<<y<<"="<<add(x, y)<<endl; break; case '-': cin>>x; cin>>y; cout<<x<<"-"<<y<<"="<<subtract(x, y)<<endl; break; case '/': cin>>x; cin>>y; cout<<x<<"/"<<y<<"="<<divide(x, y)<<endl; break; case '*': cin>>x; cin>>y; cout<<x<<"*"<<y<<"="<<multiply(x, y)<<endl; break; case 'e': return 0; default: cout<<"Sorry, try again"<<endl; } } return 0;}
Later ion in the program it use the case senario which i understand, then it goes on to tell the computer what to do in each case, i honestly dont no why they are there at the start.
im sorry for this proabably being a really low question but i dnt no lol



LinkBack URL
About LinkBacks



( its getting late , better go to sleep )