c ++ overloaded area function with do while loop










-2














input



R r
8 0
0 9.9
5 -1
3.8 7.2


its giving me these errors



main.cpp: In function ‘int main()’:
main.cpp:31:26: warning: ‘radius’ may be used uninitialized in this function [-Wmaybe-uninitialized]
} while (radius <= 1);
~~~~~~~^~~~
main.cpp:40:24: warning: ‘length’ may be used uninitialized in this function [-Wmaybe-uninitialized]
while (length <= 1 && width <= 1);
~~~~~~~^~~~
main.cpp:40:38: warning: ‘width’ may be used uninitialized in this function [-Wmaybe-uninitialized]
while (length <= 1 && width <= 1);
~~~~~~^~~~


#include<iostream>
#include <iomanip>
using namespace std;

// function prototype
double calculateArea(double);
double calculateArea(double, double);

int main()

// variables
char shape;
double radius, length, width, area;

do

cin >> shape;

while ( shape != 'c' && shape != 'r');

if (shape == 'c')

do

//input value for radius and validate

while (radius <= 1);

// call calculate area with radius
area =(calculateArea(radius));
//output area
cout << "Area of a circle with radius " << radius << " is " << area << endl;

else // calculate the area of a rectangle

// input values for length and width and validate them
while (length <= 1 && width <= 1);
// call calculate area with length and width
area = calculateArea(length, width);
// output area
cout << "Area of a rectangle with length " << length << " and width " << width << " is " << area << endl;

return 0;


// functions
double calculateArea(double radius)

double area;
area = 3.14159 * radius * radius;
return area;


double calculateArea( double length, double width)

double area;
area = length * width;
return area;










share|improve this question



















  • 1




    The line //input value for radius and validate should be replaced by proper code. Because right now there is no assignement of variable radius so it is totally normal that the compiler complains that this value is uninitialized...
    – Gabriel Devillers
    Nov 11 '18 at 22:02
















-2














input



R r
8 0
0 9.9
5 -1
3.8 7.2


its giving me these errors



main.cpp: In function ‘int main()’:
main.cpp:31:26: warning: ‘radius’ may be used uninitialized in this function [-Wmaybe-uninitialized]
} while (radius <= 1);
~~~~~~~^~~~
main.cpp:40:24: warning: ‘length’ may be used uninitialized in this function [-Wmaybe-uninitialized]
while (length <= 1 && width <= 1);
~~~~~~~^~~~
main.cpp:40:38: warning: ‘width’ may be used uninitialized in this function [-Wmaybe-uninitialized]
while (length <= 1 && width <= 1);
~~~~~~^~~~


#include<iostream>
#include <iomanip>
using namespace std;

// function prototype
double calculateArea(double);
double calculateArea(double, double);

int main()

// variables
char shape;
double radius, length, width, area;

do

cin >> shape;

while ( shape != 'c' && shape != 'r');

if (shape == 'c')

do

//input value for radius and validate

while (radius <= 1);

// call calculate area with radius
area =(calculateArea(radius));
//output area
cout << "Area of a circle with radius " << radius << " is " << area << endl;

else // calculate the area of a rectangle

// input values for length and width and validate them
while (length <= 1 && width <= 1);
// call calculate area with length and width
area = calculateArea(length, width);
// output area
cout << "Area of a rectangle with length " << length << " and width " << width << " is " << area << endl;

return 0;


// functions
double calculateArea(double radius)

double area;
area = 3.14159 * radius * radius;
return area;


double calculateArea( double length, double width)

double area;
area = length * width;
return area;










share|improve this question



















  • 1




    The line //input value for radius and validate should be replaced by proper code. Because right now there is no assignement of variable radius so it is totally normal that the compiler complains that this value is uninitialized...
    – Gabriel Devillers
    Nov 11 '18 at 22:02














-2












-2








-2







input



R r
8 0
0 9.9
5 -1
3.8 7.2


its giving me these errors



main.cpp: In function ‘int main()’:
main.cpp:31:26: warning: ‘radius’ may be used uninitialized in this function [-Wmaybe-uninitialized]
} while (radius <= 1);
~~~~~~~^~~~
main.cpp:40:24: warning: ‘length’ may be used uninitialized in this function [-Wmaybe-uninitialized]
while (length <= 1 && width <= 1);
~~~~~~~^~~~
main.cpp:40:38: warning: ‘width’ may be used uninitialized in this function [-Wmaybe-uninitialized]
while (length <= 1 && width <= 1);
~~~~~~^~~~


#include<iostream>
#include <iomanip>
using namespace std;

// function prototype
double calculateArea(double);
double calculateArea(double, double);

int main()

// variables
char shape;
double radius, length, width, area;

do

cin >> shape;

while ( shape != 'c' && shape != 'r');

if (shape == 'c')

do

//input value for radius and validate

while (radius <= 1);

// call calculate area with radius
area =(calculateArea(radius));
//output area
cout << "Area of a circle with radius " << radius << " is " << area << endl;

else // calculate the area of a rectangle

// input values for length and width and validate them
while (length <= 1 && width <= 1);
// call calculate area with length and width
area = calculateArea(length, width);
// output area
cout << "Area of a rectangle with length " << length << " and width " << width << " is " << area << endl;

return 0;


// functions
double calculateArea(double radius)

double area;
area = 3.14159 * radius * radius;
return area;


double calculateArea( double length, double width)

double area;
area = length * width;
return area;










share|improve this question















input



R r
8 0
0 9.9
5 -1
3.8 7.2


its giving me these errors



main.cpp: In function ‘int main()’:
main.cpp:31:26: warning: ‘radius’ may be used uninitialized in this function [-Wmaybe-uninitialized]
} while (radius <= 1);
~~~~~~~^~~~
main.cpp:40:24: warning: ‘length’ may be used uninitialized in this function [-Wmaybe-uninitialized]
while (length <= 1 && width <= 1);
~~~~~~~^~~~
main.cpp:40:38: warning: ‘width’ may be used uninitialized in this function [-Wmaybe-uninitialized]
while (length <= 1 && width <= 1);
~~~~~~^~~~


#include<iostream>
#include <iomanip>
using namespace std;

// function prototype
double calculateArea(double);
double calculateArea(double, double);

int main()

// variables
char shape;
double radius, length, width, area;

do

cin >> shape;

while ( shape != 'c' && shape != 'r');

if (shape == 'c')

do

//input value for radius and validate

while (radius <= 1);

// call calculate area with radius
area =(calculateArea(radius));
//output area
cout << "Area of a circle with radius " << radius << " is " << area << endl;

else // calculate the area of a rectangle

// input values for length and width and validate them
while (length <= 1 && width <= 1);
// call calculate area with length and width
area = calculateArea(length, width);
// output area
cout << "Area of a rectangle with length " << length << " and width " << width << " is " << area << endl;

return 0;


// functions
double calculateArea(double radius)

double area;
area = 3.14159 * radius * radius;
return area;


double calculateArea( double length, double width)

double area;
area = length * width;
return area;







c++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 '18 at 22:15









barbsan

2,14811122




2,14811122










asked Nov 11 '18 at 21:09









Louis Castillo

1




1







  • 1




    The line //input value for radius and validate should be replaced by proper code. Because right now there is no assignement of variable radius so it is totally normal that the compiler complains that this value is uninitialized...
    – Gabriel Devillers
    Nov 11 '18 at 22:02













  • 1




    The line //input value for radius and validate should be replaced by proper code. Because right now there is no assignement of variable radius so it is totally normal that the compiler complains that this value is uninitialized...
    – Gabriel Devillers
    Nov 11 '18 at 22:02








1




1




The line //input value for radius and validate should be replaced by proper code. Because right now there is no assignement of variable radius so it is totally normal that the compiler complains that this value is uninitialized...
– Gabriel Devillers
Nov 11 '18 at 22:02





The line //input value for radius and validate should be replaced by proper code. Because right now there is no assignement of variable radius so it is totally normal that the compiler complains that this value is uninitialized...
– Gabriel Devillers
Nov 11 '18 at 22:02













1 Answer
1






active

oldest

votes


















0














The error message is clear: radius (on if branch) and length and width may be used uninitialized (on else branch).



Check what are you parsing from user input.






share|improve this answer




















  • Ok and how would i fix that im still new to C++ programming
    – Louis Castillo
    Nov 11 '18 at 21:47










  • You probably want to ask the user for them after know if he wants to calculate a circle or a rectangle, didn't?
    – LuisGP
    Nov 11 '18 at 21:48











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253260%2fc-overloaded-area-function-with-do-while-loop%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The error message is clear: radius (on if branch) and length and width may be used uninitialized (on else branch).



Check what are you parsing from user input.






share|improve this answer




















  • Ok and how would i fix that im still new to C++ programming
    – Louis Castillo
    Nov 11 '18 at 21:47










  • You probably want to ask the user for them after know if he wants to calculate a circle or a rectangle, didn't?
    – LuisGP
    Nov 11 '18 at 21:48
















0














The error message is clear: radius (on if branch) and length and width may be used uninitialized (on else branch).



Check what are you parsing from user input.






share|improve this answer




















  • Ok and how would i fix that im still new to C++ programming
    – Louis Castillo
    Nov 11 '18 at 21:47










  • You probably want to ask the user for them after know if he wants to calculate a circle or a rectangle, didn't?
    – LuisGP
    Nov 11 '18 at 21:48














0












0








0






The error message is clear: radius (on if branch) and length and width may be used uninitialized (on else branch).



Check what are you parsing from user input.






share|improve this answer












The error message is clear: radius (on if branch) and length and width may be used uninitialized (on else branch).



Check what are you parsing from user input.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 '18 at 21:16









LuisGP

336110




336110











  • Ok and how would i fix that im still new to C++ programming
    – Louis Castillo
    Nov 11 '18 at 21:47










  • You probably want to ask the user for them after know if he wants to calculate a circle or a rectangle, didn't?
    – LuisGP
    Nov 11 '18 at 21:48

















  • Ok and how would i fix that im still new to C++ programming
    – Louis Castillo
    Nov 11 '18 at 21:47










  • You probably want to ask the user for them after know if he wants to calculate a circle or a rectangle, didn't?
    – LuisGP
    Nov 11 '18 at 21:48
















Ok and how would i fix that im still new to C++ programming
– Louis Castillo
Nov 11 '18 at 21:47




Ok and how would i fix that im still new to C++ programming
– Louis Castillo
Nov 11 '18 at 21:47












You probably want to ask the user for them after know if he wants to calculate a circle or a rectangle, didn't?
– LuisGP
Nov 11 '18 at 21:48





You probably want to ask the user for them after know if he wants to calculate a circle or a rectangle, didn't?
– LuisGP
Nov 11 '18 at 21:48


















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253260%2fc-overloaded-area-function-with-do-while-loop%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo