Hi, there is a problem in the program, apparently it only gives me tab*1 = value ,
while I want table value upto 10, please help what I got wrong with the program?
#include<iostream>
using namespace std;
int table(int);
main()
{
int n,res;
cout<<"Please enter the value for table:=";
cin>>n;
table(n);
}
int table(int n)
{
for(int c=1;c<=10;c++)
{
int res=n*c;
cout<<n<<"*"<<c<<"="<<res<<endl;
return res;
Oh,I used return in the main body and the program works !!
But in my book , they've used return in the function body and the loops too!with different programs, can you tell me the difference when to use return in the main body and when in the Function body?? Thanks!
Can you help me with this program too and tell me what and where to put the return thingy?? Its very confusing to me,.
#include<iostream>
using namespace std;
float calculator(int,char,int);
main()
{ int a,b,op;
cout<<"Calculator"<<endl;
cout<<"Please enter the first no."<<endl;
cin>>a;
cout<<"Please enter the operator"<<endl;
cin>>op;
cout<<"Please enter the 2nd no."<<endl;
cin>>b;
calculator(a,op,b);
}
float calculator(int a,char op,int b)
{
switch(op)
{
case '+':
{
cout<<a+b<<endl;
break;
You should use return in every function. main is a function. Your function table is a function.
Your function table claims that it returns an int. But it doesn't. What you're trying to do here (writing a function) is beyond your current knowledge level. You need to go back and learn about functions.
You're also using an incorrect form of main. main() is wrong. It should be int main()
---
Note for other people; yes, yes, I know that there are cases where you don't have to explicitly write return. But for a beginner, at this level of knowledge, "always" is a pretty solid answer that can't go wrong.
The reason why it doesn't work is in this case op. You let the user enter a numeric (int) value. But you pass it as a textual (char) value. That doesn't work -> Make op char op;