1

I'm very new to coding (like one day ago), so you can pretty much assume I know nothing. I'm finding it very hard to debug my extremely simple programs and most of the help I've seen online is either over my head or too specific to the program.

This is the code I'm working on now.

/*
 * LogBase8.cpp
 *
 *  Created on: Feb 13, 2015
 *      Author: Holly
 */
//This program calculates the log base 8 of a number.

#include <iostream>
#include <math.h>
#include <string>

using namespace std;

//Declare variables and constants.
float x, log_8_x;

int main()
{

//Prompt user to input number.
cout << "This program will calculate the log base 8 of a number. Input number to calculate" << endl;
cin >> x;

//Calculate log_8_x.
log_8_x = log(x) / log(8);

//Print log_8_x.
cout << "The log base 8 of " << x << " is " << log_8_x << endl;

//End main.
return (0);

}

I have an error in the log_8_x = log(x) / log(8); line that says

no match for 'operator=' (operand types are 'std::basic_istream<char>::__istream_type {aka std::basic_istream<char>}' and 'double') 

I'm using Eclipse, if that's relevant.

  • 3
    [Works for me](http://ideone.com/Kwe7mg) if I fix the broken formatting, and gives completely different errors if I don't. Are you sure this is the code you're compiling? Or does your real code say something like `cin = x;`? Or declare `log_8_x` as something other than `float`? – Mike Seymour Feb 13 '15 at 11:58
  • If you're just starting, I suggest you follow a [good book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) for learninig. – Angew is no longer proud of SO Feb 13 '15 at 11:59
  • Mike Seymour, I just copy and pasted it right out of Eclipse. – Holly Evans Feb 13 '15 at 12:01
  • Angew, I'm in a college course right now, just definitely still in the early stages. Not sure how much our textbook is helping me – Holly Evans Feb 13 '15 at 12:03
  • Any chance you have line wrapping turned on in your editor and there's no real line break in your code? – Angew is no longer proud of SO Feb 13 '15 at 12:17
  • Well the wrapping is only here on the forum because the line is too long to fit. It's just one line in my program – Holly Evans Feb 13 '15 at 12:20
  • 1
    @HollyEvans There is no line wrapping in code blocks here. If it's just one line in your program, *please edit the question to reflect that.* You're confusing everybody. – Angew is no longer proud of SO Feb 13 '15 at 12:21
  • I'm sorry. I am also confused. Didn't know I did that – Holly Evans Feb 13 '15 at 12:24
  • 1
    This is not your real code! – Lightness Races in Orbit Feb 13 '15 at 12:24
  • @LightnessRacesinOrbit Then what is my real code? This is exactly what I typed in. I just copy and pasted it – Holly Evans Feb 13 '15 at 12:25
  • 1
    After the edit, [your code works](http://coliru.stacked-crooked.com/a/0791ee98e47d7807). So the problem must be in something you haven't shown. – Angew is no longer proud of SO Feb 13 '15 at 12:26
  • Any chance you have `log` defined as a macro somewhere? Try looking at the preprocessed output (`gcc -E`) and see what the code in `main` looks like after macro substitution. – Angew is no longer proud of SO Feb 13 '15 at 12:27
  • BTW, use of Eclipse is not relevant. If anything, your compiler might be. – Angew is no longer proud of SO Feb 13 '15 at 12:29
  • Okay, I edited the question and added the only other things on the whole page. – Holly Evans Feb 13 '15 at 12:39
  • I just installed everything like 3 hours ago, and nothing has ran yet. I've built something without error messages, but it wouldn't run. I assumed I was coding wrong, but I'm seeing now that I probably messed up the installation. I installed Visual Studios originally but I was getting all kinds of errors about not being able to access the libraries and I couldn't fix them, so I installed MinGW instead, but I'm sure something got mixed up along the way. – Holly Evans Feb 13 '15 at 12:39
  • 3
    @HollyEvans: Nope, because you are not invoking `=` on an istream anywhere in this code! The error suggests that in your real code `log_8_x` is an `istream`. Do you have `std::cin = log(x) / log(8);` in some other source file, by accident? – Lightness Races in Orbit Feb 13 '15 at 13:07
  • I don't have any other source files? I made a new C++ project and then created one source file. I typed what is above and then got the error message when I tried to compile it. – Holly Evans Feb 13 '15 at 14:33
  • Can you try simplifying it further? Such as replacing the offending line with just `log_8_x = x / 8.0;` and similar, trying it after each step, until the error disappears? Then post when this happened, it might help pinpoint the problem. – Angew is no longer proud of SO Feb 13 '15 at 15:32
  • @HollyEvans: I can't really help you any further. I've told you what the situation is and can't do anything about it from here! Good luck. – Lightness Races in Orbit Feb 13 '15 at 17:34

1 Answers1

0

You have other errors as stated in your question, but anyway putting a \ to escape the newline appearing in the string literal here

cout << "This program will calculate the log base 8 of a number. Input \

fixes your compilation errors.

See fully working sample here please.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190