I recently started learning C++. I am going over a book and one thing that I am struggling little bit is return type functions. I am working on this program and my problem is that when i am trying to assign return value of selectShape() function to an int, instead of just assigning the value in the main function, it is also running the whole function all over again. How can I get the return value of selectShape() and simple assign to local variable inside the main function?
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
usingnamespace std;
void welcome();
void getInfo (string &, string &);
int selectShape();
void getLenWid(double &, double &);
double calcSqFeet(double,double);
double getDiam();
double calcSqFeet(double);
constdouble PI = 3.14;
int main(){
string name, telNumber;
double len, wid;
welcome();
getInfo(name, telNumber);
selectShape();
int floorType = selectShape(); //contains the choice of the customer
double diam = getDiam(); //contains the diameter of the circular floor
}
void welcome(){
cout<<"\tWelcome to Concrete Pro, the best supplier of concrete floors in the country!\n";
cout<<"\t\t\tWe have been providing our service for over 75 years!\n\t\t\t\tWe are not finished until you are satiffied!\n";
}
void getInfo(string &name, string &telNumber){
cout<<"Please enter your full name: "<<endl;
cin>>name;
cout<<"Please enter your telephone number: (ex: 555.555.5555)"<<endl;
cin>>telNumber;
}
int selectShape(){
int select;
cout<<"Estimate\n\n";
cout<<"To describe the shape of the floor, please enter 1 or 2:"<<endl;
cout<<"1. Rectangular\n2. Circular"<<endl;
cout<<"Selection: ";
cin>>select;
if (select<1||select>2){
cout<<"Please try valid input"<<endl;
}
return select;
}
void getLenWid(double &len, double &wid){
cout<<"Please input the length of your floor:"<<endl;
cin>>len;
cout<<"Please input the width of your floor:"<<endl;
cin>>wid;
}
double calcSqFeet(double len,double wid){
double sqFeet = len * wid;
return sqFeet;
}
double getDiam(){
double diam;
cout<<"Please enter the diameter of your floor:"<<endl;
cin>>diam;
return diam;
}
double calcSqFeet(double diam){
double radius = diam/2;
double sqFeet = PI * radius * radius;
return sqFeet;
}
yes I do, my question is are there ways to get the return value of selectShape() without running it twice. if you print floorType you will get the return value of selectShape()