|
-
Nov 16th, 2002, 12:04 PM
#1
Thread Starter
Fanatic Member
Warnings about conversions
I keep getting warnings about variable conversions, but dunno how to fix them. Can someone have a look and possibly fix it for me (very easy code)?
Warnings:
main.cpp(10) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
main.cpp(19) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
main.cpp(57) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
main.cpp(59) : warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
Code:
Code:
#include <iostream.h> // input output
#define PI 3.14159
// Function for calculating the area of a circle
float area (float r)
{
float a;
a = PI * r * r;
return(a);
}
// Function for calculating the circumference of a circle
float circumference (float r)
{
float a;
a = 2 * PI * r;
return(a);
}
// Program start
int main ()
{
// Declare needed variables
int type;
float answer;
int n = 0;
int radius;
//Keep looping until a valid choice has been made
do {
cout << "What would you like to calculate?\n";
cout << "1. Circumference\n";
cout << "2. Area\n";
cout << "Enter your choice: ";
cin >> type;
// Check if a valid choice has been made
if (type == 1 || type == 2) {
// A valid choice has been made, exit loop
break;
} else {
// Invalid choice, display error
cout << "Invalid Choice! Please try again\n\n";
}
} while (n != 1);
// Ask for radius
cout << "Please enter a radius for the circle: ";
cin >> radius;
// Use the functions to calculate
if (type == 1) {
answer = circumference(radius);
} else if (type == 2) {
answer = area(radius);
}
//Display answer
cout << "The answer is: " << answer;
//Exit Program
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|