hello this code seems to give me wrong results and i carnt figure out why :(

#include <iostream>
int main() {
    
    float pi = 3.142;
    char area;
    float diameter;
    
    area = diameter * pi;
    
    std::cout << "Hello. Please imput the diameter of your circle... ";
    std::cin  >> diameter;
    
    std::cout << "The area of your circle is " << 'area' << ".\n";    
    std::cin.get();
    return 0;
}

Fill a glass with water (or what else) then drink, not vice versa ;)

Calculate a circle area AFTER its diameter request.
Output the area variable, not a wrong character literal 'area'...

#include <iostream>
int main() {
    
    float pi = 3.142;
    char area;
    float diameter;
    
    std::cout << "Hello. Please imput the diameter of your circle... ";
    std::cin  >> diameter;
    
    area = diameter * pi;
    
    std::cout << "The area of your circle is " << area;    
    std::cin.get();
    return 0;
}

gives me a wierd symbol for the area? :( why is this i cannot see anything wrong with my code (newbie)

>gives me a wierd symbol for the area?
area is declared as a char, and cout is assuming you want to print a character rather than the integral value. Change char area; to int area; and you'll get a slightly more reasonable result.

Thank you that has gave me a realistic result but it doesnt show the deicmals just rounds it to a whole number ? is there anyway to let it do this thank you once again

and to stop the program flashing of the screen?

>...why is this i cannot see anything wrong with my code...
Oh, this harmful Daniweb engine! I see 'area' in the OP snippet but area in the post #3 code ;)
By the way, change char area; to float area; ...

Woop :D everything works fine now, except the program flashes off straight away lol :( ? should std::cin.get(); stop that happening?

anyone?

Insert std::cin.ignore(1000,'\n'); after std::cin >> diameter;

Thank you man :D

I believe you still have a problem with the math?

Circumference = 2 .0 * PI * Radius;
Area = PI * Radius * Radius;

To borrow a very old math joke, "Pie aren't square, Pie are Round!"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.