I am currently on my 6th week of learning C++, and in class, we're learning about how to effectively use the different types of functions to transfer values between themselves and _main.
I'm fairly confident in using the different types of functions, but in one case, I'm getting an error that I'd like help understanding. The program also doesn't output the correct numbers.
My only Error: warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
----
Requirements for the program:
01) Input the radius of a circle.
02) Output the Circumference
03) Output the Area
04) Use the following functions:
--- void Banner() function
--- void getValue() function
--- value returning computeCircumference() function
--- void computeArea() function
--- void outputData() function
--- value returning goAgain() bool function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#include "stdafx.h"
#include <iostream>
#include <sstream>
using namespace std;
void banner();
void getValue (int);
int computeCircumference(int);
void computeArea(int, int);
void outputData(int, int, int);
bool goAgain();
int main(){
int radius = ' ';
int area = ' ';
banner();
do{
getValue(radius);
int circumference = computeCircumference (radius);
computeArea (radius, area);
outputData (radius, circumference, area);
} while ( goAgain() );
return 0;
}
void banner(){
cout << "======================================================" << endl;
cout << "--------------Welcome to Project Circle!--------------" << endl;
cout << "------------------------------------------------------" << endl;
cout << "This program will allow you to input a circle's raidus" << endl;
cout << "------------------------------------------------------" << endl;
cout << "---and will then output the circumference and area.---" << endl;
cout << "------------------------------------------------------" << endl;
cout << "---------------------Let's begin!---------------------" << endl;
cout << "======================================================" << endl;
cout << endl; cout << endl;
}
void getValue(int R1){
cout << "Please input the radius of your circle: ";
cin >> R1;
}
int computeCircumference(int R2){
int C1;
int pi = 3.14;
C1 = (2 * pi * R2);
return C1;
}
void computeArea(int R3, int A1){
int pi = 3.14;
A1 = (pi * R3 * R3);
}
void outputData(int R4, int C2, int A2){
cout << "======================================================" << endl;
cout << "--------------Information on your circle--------------" << endl;
cout << "------------------------------------------------------" << endl;
cout << "Radius--------: " << R4 << endl;
cout << "Circumference-: " << C2 << endl;
cout << "Area----------: " << A2 << endl;
cout << "------------------------------------------------------" << endl;
cout << "-------------Your circle is now complete!-------------" << endl;
cout << "======================================================" << endl;
cout << endl; cout << endl;
}
bool goAgain(){
char run2;
cout << "Do you want to run this program again? (y/n): ";
cin >> run2;
cout << endl; cout << endl;
if ( run2 == 'y' || run2 == 'Y' )
return true;
else
return false;
}
/*
Personal Notes on Function Types
01) int P( ); Calls function P
02) int P(x); Sends x to function P, Calls function P
03) N = int P( ); Calls function P, sets N equal to return value
04) N = int P(x); Sends x to function P, Calls function P, sets N equal to return value
05) void P( ); Calls function P
06) void P(x); Sets x equal to function P's defined values
*/
| |