Jump to content


Photo

c++ noob


  • Please log in to reply
5 replies to this topic

#1 the.cheese

the.cheese

    Join the cheese army

  • Members
  • PipPipPip
  • 663 posts
  • Gender:Male
  • Location:Idaho

Posted 31 May 2012 - 08:41 PM

#include <iostream>
using namespace std;
int x;
int y;
int z;
	bool boo = false;
int answer;
void main()
{
	cout << "Hey\n";
	while (!boo);
	{ 
		cout << "How are you\n";
		cin >> x;
		if (x == "good")
		{
			boo = true;
		}
		else 
		{
			x = false
			y = "thats unfortunate";

		}
	}
	answer = "thats good";
		cout << "well" << answer << endl;
		system("pause");
	return 0;
}










ok idk what im doing wrong, i want it to say "how are you" and it will repeatedly ask you that until you say good





1>------ Build started: Project: screwing around, Configuration: Debug Win32 ------
1>  driver.cpp
1> error C2446: '==' : no conversion from 'const char *' to 'int'
1>          There is no context in which this conversion is possible
1> error C2040: '==' : 'int' differs in levels of indirection from 'const char [5]'
1>: error C2146: syntax error : missing ';' before identifier 'y'
1>: error C2440: '=' : cannot convert from 'const char [18]' to 'int'
1>          There is no context in which this conversion is possible
1>error C2440: '=' : cannot convert from 'const char [11]' to 'int'
1>          There is no context in which this conversion is possible
1>: error C2562: 'main' : 'void' function returning a value
1>           see declaration of 'main'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


if you need to you can skype me, but just ask for that
it seems that EVERY gun these days shoots ropes, money, tits, lasers, etc....put this in your sig if yours still shoots the other team...

Why does TechPB attempt to solve all problems with shitting on stuff? Hahahaha.


#2 Stix

Stix

    TechPB Lurker

  • Members
  • PipPipPipPipPip
  • 1,509 posts
  • Gender:Male
  • Location:A Cave with WIFI

Posted 31 May 2012 - 08:43 PM

I'm very bad with C++, but it looks like your Boolean isn't correct. I could be wrong though.
xfire-stix9693
Ps3 - SLYGATHOR (LittleBigPlanet, Burnout Paradise, Team Fortress2, Killzone 2)
Wii - 5318 0896 2208 0310
Steam - slygathore
Building a computer is like playing with Legos, the pieces only fit one way
Posted Image

#3 the.cheese

the.cheese

    Join the cheese army

  • Members
  • PipPipPip
  • 663 posts
  • Gender:Male
  • Location:Idaho

Posted 31 May 2012 - 08:45 PM

I'm very bad with C++, but it looks like your Boolean isn't correct. I could be wrong though.


probably, i started yesterday and have only had 2 successful programs
it seems that EVERY gun these days shoots ropes, money, tits, lasers, etc....put this in your sig if yours still shoots the other team...

Why does TechPB attempt to solve all problems with shitting on stuff? Hahahaha.


#4 Blade of grass

Blade of grass

    Master Member

  • Members
  • PipPipPipPipPipPip
  • 3,224 posts
  • Gender:Male


Posted 01 June 2012 - 06:46 AM

I think that === (not ==) checks if a statement is true, but then again, that maybe just be the JavaScript I'm remembering.

Edited by Blade of grass, 01 June 2012 - 06:46 AM.

all my legos are stored at my parents hose... so that wont be happening....

48fhih.png

#5 the.cheese

the.cheese

    Join the cheese army

  • Members
  • PipPipPip
  • 663 posts
  • Gender:Male
  • Location:Idaho

Posted 02 June 2012 - 12:44 AM

fixed it thanks though
it seems that EVERY gun these days shoots ropes, money, tits, lasers, etc....put this in your sig if yours still shoots the other team...

Why does TechPB attempt to solve all problems with shitting on stuff? Hahahaha.


#6 CrazyLittle

CrazyLittle

    That's 65% more bullet, per bullet.

  • Root Admin
  • PipPipPipPipPipPipPipPip
  • 8,116 posts
  • Gender:Male

Posted 02 June 2012 - 01:51 AM

Cheese, I took the liberty of converting your post to code tags.

I think that === (not ==) checks if a statement is true, but then again, that maybe just be the JavaScript I'm remembering.

"===" is a PHP or Javascript comparison operator. You want "==" which is a standard C comparison operator. A single "=" is an assignment operator.


else 
                {
                        x = false
                        y = "thats unfortunate";

                }
You forgot a semicolon after false.

int x;
int y;
int z;
        bool boo = false;
int answer;
void main()
{
        cout << "Hey\n";
        while (!boo);
        { 
                cout << "How are you\n";
                cin >> x;
                if (x == "good")
                {
                        boo = true;
                }

At the top you've declared x, y and z as integers, and then you tried to assign strings to them. That's why you're getting this comparison compiler error:

'==' : no conversion from 'const char *' to 'int'
There is no context in which this conversion is possible


You can't compare dissimilar variable types in standard C/C++ without overloading the comparison operator. Since x/y/z are supposed to be strings, you should probably declare them as such.

if (x == "good")
By the way, this comparison will never match under normal circumstances, since neither char* x nor int x would ever match "good" from a cin input.

Feedback | Everything you need to know about Loctite | I have too many guns to list. Click here to see them.
Posted Image
PrometheanFlame - If I had to pick one of us to survive the rapture/nuclear apocalypse, I'd choose you.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users