I started c++ a few days ago and I am trying to make this program for my math class just to test myself.

This is my code.

#include <iostream>
using namespace std;

int main ()

{
    int goldennumber;
    int finalnumber;
    int ratio;

    cout<<"Welcome to Easy Golden Ratio Finder!\n";
    cout<<"\n";
    cout<<"\n";
    cout<<"\t Please enter the length of the rectangle: \n";
    cin>>"goldennumber";
    cin.get();

    cin.ignore();

    ratio = 0.618;
    finalnumber = goldennumber * ratio;

    cout<<"Your number is: "<< finalnumber <<"\n";


    return 0;

}

I'm trying to make this console program where you enter a number and the program does an equation for you and you get the final number.

I tried compiling and this are the error I get:

  • error: ambiguous overload for 'operator>>' in std::cin >> "goldennumber"'

Can someone explain what I did wrong and what this error means so I know how to fix it in the future?

Ancient Dragon commented: Thanks for using code tags on your very first post :) +21

Recommended Answers

All 4 Replies

>> cin>>"goldennumber";
remove the quotes. it should be like this: cin>>goldennumber;

#include <iostream>
using namespace std;

int main ()

{
    float goldennumber, dummy;
    float finalnumber;
    float ratio = 0.618;

    cout<<"Welcome to Easy Golden Ratio Finder!\n";
    cout<<"\n";
    cout<<"\n";
    cout<<"\t Please enter the length of the rectangle: \n";
    cin >> goldennumber;
    
    finalnumber = goldennumber * ratio;
    cout<<"Your number is: "<< finalnumber <<"\n";
    cin >> dummy;

    return 0;

}

This is will work. I made a few changes.
The compiler error is caused because goldennumber was in quotes. Quotes are reserved for stirngs, and goldennumber is an integer.

Since the answer will most likely be a decimal, I changed the integers to floats. Floats are basically the exact same thing as integers; they can just take decimal values - and they're a little bigger.

I defined ratio earlier just because it's easier to read that way.

and I really don't know what cin.get() is for, but I do know that it's unnecessary there.

Ok thanks I'll try that.

Thank you alot. It Worked. I learned alot in these past 10 minutes and i thank you for that.

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.