Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6577581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:39:18+00:00 2026-05-25T15:39:18+00:00

You cin a value to the variable f . f could be something like:

  • 0

You cin a value to the variable f. f could be something like:

pow(5.957,-X*X*X*X)-cos(X*X) +20*sin(X*X)

or some other complicated math function. I also tried to declare it directly as such.

f = pow(5.957,-X*X*X*X)-cos(X*X) +20*sin(X*X);
std::cout << "Bisection method on function,  f = " << f << " "<<std::endl;

The output is on both MinGW and VS2010:

f = nan

How do I get cout to print f on the screen?

I declared f as such

double F(double X) { double f; f =  pow(5.957,-X*X*X*X)-cos(X*X) +20*sin(X*X); return f; }

I’m basically writing a C++ program to perform different numerical methods for finding roots on the function: bisection, Monte Carlo, Newtwon’s method etc. Those work, but I want to display the function to the user after he types it in, and it just shows up as NaN.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:39:19+00:00Added an answer on May 25, 2026 at 3:39 pm

    From the looks of it, you are trying to define f as an actual mathematics function (in the direct way of doing it). That definitely won’t work.

    But if you have a string, then f will output a string, ignoring the mathematics function.

    Remember, unlike other programming languages, C++ is very…temperamental.

    You can’t assign a character to an int and vice versa. But string can hold anything because it is only a piece of text.

    Try using getline…just wait a sec and I’ll go get my book..

    Edit: Okay. If you use getline (cin, foo);, where foo is defined as string foo and you include <string>, this should work. Is that what your coding originally looked like?

    Edit2: You should still be able to use stream to convert from a string back and forth…but I’d need somebody more experienced than me to confirm that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using split function and assigning the value in a variable and running
As in, can I pass cin to any function that accepts an ifstream object?
Yesterday, I found myself writing code like this: SomeStruct getSomeStruct() { SomeStruct input; cin
I am having a problem trying to write a String Variable's value to a
Why assign a function to a variable? What's the point in assigning int x,
I'm making a short database application where people can assign variables to something. like
i am trying to get checkbox value ,using c# In grid view the datasource
The bug starts at cin.getline ( string, 25, '\n' ); or the line below
I was wondering how to use cin so that if the user does not
How do I clear the cin buffer in C++?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.