Jump to content
xisto Community
zach101

Help With C++

Recommended Posts

Hey guys i just stared learning c++ or at least attempting to so yes my knowledge of it is EXTREMLY basic however i really want to learn more about it unfortunatly i take C++ with a class of 25 other freshman (im a junior) that are just learning HTML so the help i get from my teacher is EXTREMLY limited (whoa i just said extremly in all caps twice in one post!!!) any way so the help i get is limited like i said and i was just wondering if you could look at this code and tell me what exactly is wrong with it cause i cant figure it out any help would be great.


/* chapter four review 13Zachary Everman Oct 5 */#include<iostream.h>int main(){char pw;cout << "Enter the password: "cin >> pw;if (pw == zach)cout << "You guessed it!"elsecout << "Sorry try again"return(0);}

Notice from BuffaloHELP:
You must use CODE tags when including programming language. Inserted CODE tag

Edited by BuffaloHELP (see edit history)

Share this post


Link to post
Share on other sites

Looks generally all right to me, although it depends on what you want to do. There are a couple of errors in syntax:

if (pw == zach)                        // zach needs to be inside quotes.    cout << "You guessed it!"        //You need a semi colon here.elsecout << "Sorry try again"        //You need a semi colon here.


Also, since you're trying to compare pw with zach, and zach is not a variable (I'm assuming this, else please declare zach somewhere in the beginning), pw needs to be an array of characters, not a single character. Have you done arrays yet?

G'luck and keep at it... cheers!

Share this post


Link to post
Share on other sites

nope :huh: at least i dont think i know what arrays are any way im just trying to make it that where "cin" is you can enter any thing u want if u enter zach it gives u that first cout thing other wise it says sorry please try again. After i get that part working i need to figure out how to put somthin called a { do while } statement in or somthing? im just now learning about this looping thing not tottaly grasping the conecpt though

Share this post


Link to post
Share on other sites

okay so i got it to work just fine but as soon as i put in these do while statements in it dint work so any help on where to put em?

/* chapter four review 13Zachary Everman Oct 5 */#include<iostream.h>#include <lvp\string.h>int main(){String pw;do {cout << "Enter the password: ";cin >> pw;if (pw == "zach")cout << "You guessed it!";elsecout << "Sorry try again"; } whilereturn(0);}

Share this post


Link to post
Share on other sites

Hey... the while needs a condition to go with it. You see, the idea of a do-while loop is that you're asking your compiler to excecute a sequence of statements (DO) as long as (WHILE) some condition is satistfied. For instance, you might want to add 5 to a variable till the value of that variable reaches, say, 100. Your program would look like this:

#include<whatever.h>void main(){         int i = 0;         do{                        i=i+5;          }while(i<=100);}


I'm curious as to what book you are using to study your C++. Just in case you are not entirely satisfied, you could look at the following free resources:

http://www.freeprogrammingresources.com/cppbooks.html
http://www.thefreecountry.com/documentation/onlinecpp.shtml


You could, in particular, try this:

A Beginner's Guide to C++

You can download Postscript versions of this draft version of a book designed for an introductory computer science course in Australia. The electronic book is designed for newcomers to C++ wishing to learn the C++ programming language. If you need a free Postscript viewer, you might want to try Ghostview.

Of course, you could just skim CH1 and go straight to Ch2 which seems more relevant right now.

or this:

http://forums.xisto.com/no_longer_exists/
[Link to a book called Thinking in C++, Vol 1]

Keep us updated on your progress :huh:
Cheers!

Share this post


Link to post
Share on other sites

Thanks alot and im using a buck called "A Guide to Programming in C++" its made by lawrenceeville press and its autor type people are Tim Corica Beth Brown and Bruce Presleyand once again thanks for the help

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.