Tuesday, July 14, 2009

Help with c++ Huffman BTree!?

Hey guys with the folowing protoype and function,


I am getting this error, which says...





In function `void getHuffmangetHuffman(BTree*, std::string%26amp;, std::string*)':


error: invalid initialization of non-const reference of type 'std::string%26amp;'


from a temporary of type 'std::basic_string%26lt;char, std::char_traits%26lt;char%26gt;,


std::allocator%26lt;char%26gt; %26gt;'





can someone please help me out......


here is my code below!








void getHuffman(BTree* node, string%26amp; s, string sa[]);














void getHuffmangetHuffman(BTree* node, string%26amp; s,string sa[])


{


if (node != NULL)


{


if (node-%26gt;getLeftChild() == NULL %26amp;%26amp; node-%26gt;getRightChild() ==


NULL)


{


char buf[2];


buf[0] = (char)node-%26gt;getLetter();


buf[1] = 0;


string s2 = buf;


sa[node-%26gt;getLetter() - 'a'] = s2 + " = " + s;


}


getHuffman(node-%26gt;getLeftChild(), s + "1",sa);


getHuffman(node-%26gt;getRightChild(), s + "0",sa);


}


}

Help with c++ Huffman BTree!?
The second parameter of getHuffman is a parameter of type std::string%26amp;. Reference parameters need need to use actual variables in the function call. If you use a literal instead, it'll complain.





For example:


myFunction(int %26amp;nValue);





you can call it as myFunction(nX);


but not myFunction(5);


or even myFunction(nX+1);





Because 5 does not have an address, so %26amp;nValue can not be set to anything. When this happens, the compiler normally puts 5 in a temporary variable and passes the temp variable to the function instead. Same with nX+1.





You have two options:


1) make the std::string %26amp; parameter a const std::string %26amp; instead.





2) When you call the function, pass it an actual variable instead of an rvalue.

land survey

Help on c++?

I wrote a program that compute %26amp; print the Area of triangle :


#include%26lt;iostream.h%26gt;


main( )


{


const 1/2;


int b,h;


cout%26lt;%26lt;"enter b,h"%26lt;%26lt;endl;


cin%26gt;%26gt;b;


cin%26gt;%26gt;h;


cout%26lt;%26lt;"Area of Triangle="%26lt;%26lt;1/2*b*h;


}





please can any one tell me what's wrong with it .

Help on c++?
1) Remove const 1/2


2) Write b*h*1/2 instead of 1/2*b*h while printing





Your program will run











The MAIN REASON your program isn't giving right answer is you are printing 1/2*b*h. As the compiler reads from left to right and as the priority of '/' and '*' is equal, so it is taking this expression as 1/(2*b*h).





As you haven't mentioned any data type for the answer, compiler is treating it as an integer output. As 2*b*h becomes a large value, 1/(2*b*h) becomes zero (0). So your output is 0.
Reply:First remove const 1/2


It doesnt make sense





Now... since u are using 1/2.. it is a floating point value.


So just add this statement:





float area = 0.5 * b * h;


cout %26lt;%26lt; "Area of Triangle = " %26lt;%26lt; area;





Thats it ;)
Reply:It will give you error at


const 1/2


Sicne C++ does not allow "/" operator in the declaration of Const. If at all you are interested in so, try to use


() in the const declaration.


But I dont see any other error apart from this in the above code.


Any decent c++ programmers out there to translate this code?

here is doom source code for a file called d_items. Need to know what it means. Is the variables = to a graphic or animation image? Notice upstate, downstate etc, are these animations of the character shooting the gun?





static const char


rcsid[] = "$Id:$";





// We are referring to sprite numbers.


#include "info.h"





#ifdef __GNUG__


#pragma implementation "d_items.h"


#endif


#include "d_items.h"





// PSPRITE ACTIONS for waepons.


// This struct controls the weapon animations.


//


// Each entry is:


// ammo/amunition type


// upstate


// downstate


// readystate


// atkstate, i.e. attack/fire/hit frame


// flashstate, muzzle flash


//


weaponinfo_t weaponinfo[NUMWEAPONS] =


{


{


// fist


am_noammo,


S_PUNCHUP,


S_PUNCHDOWN,


S_PUNCH,


S_PUNCH1,


S_NULL


},


{


// pistol


am_clip,


S_PISTOLUP,


S_PISTOLDOWN,


S_PISTOL,


S_PISTOL1,


S_PISTOLFLASH


},


{


// shotgun


am_shell,


S_SGUNUP,


S_SGUNDOWN,


S_SGUN,


S_SGUN1,


S_SGUNFLASH1


}

Any decent c++ programmers out there to translate this code?
There is no actual code here, it does nothing. These are purely structures containing definitions. Just as you would define a variable. It doesn't do anything until you reference it again and do something with it.
Reply:It's kinda chopped off, but what it looks like to me is a set of enumerations that define the state of a weapon animation. Without more of the code, I can't tell you if this is related to graphics or animations. My guess is that it describes the entire state of a weapon at a given point in time.
Reply:can't really tell by the code you posted. It's standard coding convention that those ALL_UPPERCASE variables are constants they never get changed. S_SGUN represents the same thing in this function as it will in any other function.


Judging by the comments about the upstate and downstate, it sounds like these are arrays holding the address or something similar to the animation code. They might be pointers to it.
Reply:This code is purely definitions, it does nothing. The images are stored somewhere else, probably in an external file.


REctangle code C++ 2005 express?

Im having a hard time, can some one help me with this program??? This is my assignment, im lost


Write a program that displays a rectangle of given the length (an integer size less


than or equal to 21) and the width (an integer less than or equal to 79). Your


program should accept as input from the keyboard the character used to form the


rectangle, and the two values for the length and width of the rectangle.





Out of range input values should result in an informative error message.





Your program should process only one input case, legal or not. Termination occurs


after either the error message is printed or the diamond is drawn.





It is necessary that the program be written using loops.





Sample runs:





Rectangle drawing program


Enter the character, and length and width (eg. x 7):A 7 12


AAAAAAAAAAAA


A A


A A


A A


A A


A A


AAAAAAAAAAAA





Rectangle drawing program


Enter the character, and length and width (eg. x 7):R 3 5


RRRRR


R R


RRRRR





Rectangle drawing program


Enter the character, and length and width (eg. x 7):A 27 32


You have entered an illegal value for the length. It must be between 1 and 21.





You should use a named constant (const) to define and refer to the box size limits.


This will make it easy to modify the program at a later date if the size restriction is


changed. Write a class called Rectangle. Have the appropriate data members for


that class. Also have a constructor and a function to output the rectangle.

REctangle code C++ 2005 express?
So you need to have 2 functions, one for the header and footer block, and the other for the middle pieces. Then using math figure out how many times to do it.





psuedo code:





gets(userinput);





for ( int i = 0; i %26lt; userinput[2]; i++ )


{


int length = userinput[4];





if (userinput[2] == i || i == 0 )


drawFullCharacterRowOf ( userinput[0], length );


else


drawPartialCharacterRowOf( userinput[0] );


}








void drawFullCharacterRowOf ( char val, int length)


{


for ( int i = 0; i %26lt; length; i++ )


cout %26lt;%26lt; val %26lt;%26lt; endl;


}








This is extremely pseudo code, but you see the point I would imagine.
Reply:// TestCPPConsole.cpp : Defines the entry point for the console application.


//





#include "stdafx.h"


#define MAX_LENGTH 21


#define MAX_WIDTH 79





class Rectangle


{


private:


char m_cUseThisChar;


int m_iHeight;


int m_iWidth;





public:


Rectangle( char cUseThisChar, int iHeight, int iWidth )


{


m_cUseThisChar = cUseThisChar;


m_iHeight = iHeight;


m_iWidth = iWidth;


};





void DrawRectangle( char * szRectangle )


{


char * szTemp = ( char * ) malloc( ( m_iWidth + 2 ) * sizeof( char ) );


try


{


szRectangle[ 0 ] = 0;





memset( szTemp, 0, m_iWidth + 2 );


memset( szTemp, m_cUseThisChar, m_iWidth );


szTemp[ m_iWidth ] = '\n';





for( int iCnt = 1; iCnt %26lt;= m_iHeight; iCnt++ )


strcat( szRectangle, szTemp );


}


catch(...)


{


strcpy( szRectangle, "Error" );


}


if( szTemp != NULL )


{


free( szTemp );


szTemp = NULL;


}


};


};





int _tmain(int argc, _TCHAR* argv[])


{


char cUseThisChar;


int iHeight, iWidth;


printf( "Enter the character, and length and width (eg. x %d %d) ):\n", MAX_LENGTH, MAX_WIDTH );


scanf( "%c %d %d", %26amp;cUseThisChar, %26amp;iHeight, %26amp;iWidth );





if( iHeight %26gt; MAX_LENGTH )


{


printf( "You have entered an illegal value for the length. It must be between 1 and %d.", MAX_LENGTH );


getch();


return 1;


}


if( iWidth %26gt; MAX_WIDTH )


{


printf( "You have entered an illegal value for the width. It must be between 1 and %d.", MAX_WIDTH );


getch();


return 1;


}





Rectangle rect( cUseThisChar, iHeight, iWidth );


char * szBuffer = ( char * ) malloc( ( ( ( iWidth + 2 ) * iHeight ) + 10 ) * sizeof( char ) );


rect.DrawRectangle( szBuffer );


printf( szBuffer );


free( szBuffer );


szBuffer = NULL;


getch();


return 0;


}


======================================...


Disclaimers:


1. Content of stdafx.h file is:





//------------------------------------...


#pragma once


#define WIN32_LEAN_AND_MEAN


#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;string.h%26gt;


#include %26lt;string.h%26gt;


#include %26lt;tchar.h%26gt;


#include %26lt;conio.h%26gt;


//------------------------------------...





2. Error handling must be improved


3. Due to deprecation, functions like getch(), strcpy() etc will get warnings. Use other library methods if you are picky.


Doubt in c program?

volatile constant. this a a datatype right?? eg. const int n=1 means the value of n is going to b constant for the whole program. ant volatile just opposite.but can these exist like i mentioned above???


help if yes means how??

Doubt in c program?
first of all volatile is a C++ key word and its not for what u said..





see Wikipedia:


http://en.wikipedia.org/wiki/Volatile_va...
Reply:Welcome the famous old question. volatile and const are not mutually exclusive to each other. That is to say, these keywords can be used together to qualify a type. Both fall under the 'type qualifier' category of keywords.





const %26lt;type%26gt; var; means var is read only type for the user. the user(in this case, programmer) may not edit a const type.





volatile %26lt;type var; means that everytime something non-trivial needs to be done with the var's value, it has to be read in at that point. Its value may change in unpredictable ways thanks to 'interrupts'(%26lt;--note: this is the keyword here).





volatile const %26lt;type%26gt; var; means, var's value can change in unpredictable ways thanks to 'interrupts' but the user(programmer, in this case) may not change it by hand.





wondering where this kind of thing would be used? look at some (Linux)OS or device drivers code. they use this kind of declarations in many places.
Reply:Yes.the volatile constant may exist given that there is a separate declaration of the number else where in the program.The local scope is of most priority,more than the public and the private scope.So when decl as a constant in public or private and when in the local it is re-declared.,these r caled volatile constant


To declare a costant:


const var_name = var_value;


to decl volatile const


data_type const var_name= var_value;

survey software

I have c++ problem here is the function and its error how can I change my function?

void codfile(int *a,int n,int codlength)


{


const int memory=n*codlength/8;


int finalCod [memory]={0};


int k=0,fptr=0,cptr=0;


for(int i=0;i%26lt;n;i++)


{


int temp=a[i];


while(cptr%26lt;codlength)


{


if(fptr==8){ fptr=0;


k++;


}


finalCod [k]=finalCod[k] | temp/2;


finalCod[k]%26gt;%26gt;1;


temp/=2;


cptr++;


fptr++;


}


error in line 4: constant expression required

I have c++ problem here is the function and its error how can I change my function?
The statement


int finalCod [memory]={0};


is illegal because "memory" is a variable.


You need dynamic memory allocation:


either


int *finalCod = new int[memory];


or


int *finalCod = calloc( memory, 1 );


Do not forget to free the memory: for "new" use "delete", for "calloc" use "free()".
Reply:Yeah, what the heck is {0}?


You mean 0? Or 0th element of some array?
Reply:the code seems fine to me. chk whether the main program which generates a function call to codfile changes teh value of codlength? is codlength of type const?? u can try doing two things to remove ther error....first is directly initialize teh array to NULL and second u may try removing the const keyword.
Reply:The error is in this line:


const int memory=n*codlength/8;





memory is a const type. You cannot decide what goes into a constant type at run time. It has to be pre-decided.
Reply:Yeah, just remove const in line 3. The reason why it can't work is because you would be changing the value of memory every time you call the function, so just get rid of const. Or maybe in order for your array to work (int finalCod) with memory, it has to be also constant. So try getting rid of const when declaring memory.





Good Luck
Reply:the problem with ur function is that ur allocating memory statically without knowing exactly how much memory to allocate. this is not possible in c++. try the same thing dynamically using the 'new' operator.for eg int n=new int[];


In C++, What use do we have for constants instread of variables?

an example would be


const double PI=3.14;


for(float x=PI;whatever;x++){


cout%26lt;%26lt;x%26lt;%26lt;endl;


}





that was just an example of using constants;





but you could do the same without using constants;


double PI=3.14;


for(int x=PI;whatever;x++){


//This would also work


}








so what use do we have of using constants for somethings instread of variables

In C++, What use do we have for constants instread of variables?
Constants don't change, variables can change.





You can't mistakingly change a constant. For example like this:





if(pi=3.00){


//do something


}





If pi is a constant, you'll get an error message. If pi is a variable, you won't.
Reply:It's just so that no one else changes them. It also indicates to other programmers that the variable is never intended to change.
Reply:Variables use more memory. So if you have a large program you need to consider this.
Reply:Its just validation, it eliminates problems caused by changing variables.





It prevents you from accidentally changing its value and messing everything up. Its very professional. I must admit, I dont use them but I should do.


Beginner C++ help plz?

Write a function that accepts an array of integers and an integer that represents the size of the array. This function will reverse the order of the array. Ex:





if a[0] = 4, a[1] = 2, a[2] = 9, a[3] = 89;





After executing this function:





a[0] = 89, a[1]=9, a[2] = 2, a[3] = 4





#include %26lt;iostream%26gt;


using namespace std;





int main()


{


const int SIZE = 4;


int a[4] = {4, 2, 9, 89};





for (int count = 0; count %26lt; SIZE; count++)


b[count] = a[count];








return 0;


}





I have this so far, I can't get any farther, can u please make some changes.

Beginner C++ help plz?
This is a very very common question especially on job interviews so it is important that you have as an elegant as solution as possible.





void Reverse(int* array, int length)


{


int i, tmp;





for (i=0; i%26lt;len/2; i++)


{


tmp = array[i] ;


array[i] = array[len-i-1] ;


array[len-i-1] = tmp;


}





note there is an even more elegant solution using the ^ (xor) operation but that is not for the beginner.





**** Note I edited the second line from


array[i] = tmp


to


array[len-i-1]


}
Reply:What do you need to do here honey? What does b[count]=a[count] do ? It makes and exact copy of the array, right?


Whare you want to do is flip the array. You want that line to be something like this:


b[count]=a[SIZE-count];


This may look wrong at first, but try it out, you will be plesantly surprised.


Do the math for it and you will see what is happening.


b[0]=b[4-0]


b[1]=b[4-1]


and so on....





:)





Actually I also like the other guys answer for this one, that is a much more elegant solution.


In C++ is writing a copy constructor the same as overloading the assignment operator?

Lets say





class x{





X(const%26amp; X rhs){





y = rhs.y;


z = rhs.z;





};





private:


double y;





int z;


};








Doing that will allow for assignment too right???





Does that make


X y2;


X y1 = y2; // wont y1.X(y2) be called any way???





work how it seems like it should?





thanks!

In C++ is writing a copy constructor the same as overloading the assignment operator?
They are closely related. When you write one, you should write the other.





The other answerers are correct. The copy constructor is used when you write code like the following:





MyClass X = Y; //invokes copy constructor


MyClass X(Y); //also invokes copy constructor





whereas the operator = is called when you write code like the following:





MyClass X: //invokes default constructor


X = Y; //invokes operator =





Since you rarely see code like "MyClass X = Y", you might be tempted to skimp on the copy constructor. Don't. There's another sneaky place you often find copy constructors: passing variables by value. The standard template library does this ALL THE TIME, so if you have vectors or lists in your code, be aware of this.





MyClass Y; //invokes default constructor


DoSomething(Y); //calls copy constructor





std::vector%26lt;MyClass%26gt; myVector;





// (pretend we added a bunch of items to vector here)





myVector.push_back(Y); //invokes copy constructor. May also invoke copy constructor on other items already added if vector resizes.





std::sort(myVector); //invokes operator= on any items that move





From the programmer's standpoint, one key thing to remember is that when you write the operator =, you MUST clean up anything you're pointing at already. For example, if you have a pointer in your class, you should free that pointer before copying the value from the right-hand side. Copy constructors tend to be faster than operator= for this reason.





Hope this helps.
Reply:It will call the copy constructor but there's a different between both..copy constructor (or any other type of constructors) is called ONLY when you INITIALIZE a new instance of a certain class (statically or dynamically)..


so in your example, you used the assignment operator and the copy constructor was called because y1 was being initialized in that statement (X y1)


But, later on in the program...if you needed to write this:


y2=y1;


you will need the assignment operator overloading...and the copy constructor won't be called (No declaration/initialization here)
Reply:assignment is different from the construction of an object. Copy constructor is called when an object is being defined and is being initialized with a value. Assignment operator is called when a value is assigned to an already defined object.





Note the difference between INITIALIZATION and ASSIGNMENT.





Thus,


X y2;


X y1 = y2;


will call the copy constructor and not the assignment operator.

survey research

I need help with printing and calling a C program... PLZ HELP!!?

[HW] array of strings: Write a program to sort an array of strings into


alphabetical order. Use


const int N_MONTHS = 12;


const int STR_MAX = 20;


char month[N_MONTHS][STR_MAX] = {


"January",


"February",


"March",


"April",


"May",


"June",


"July",


"August",


"September",


"October",


"November",


"December"


};


as your test strings. Write the following functions.


● void print(char str[ ][STR_MAX], int n_str);


Write a function prints an array of strings. Parameter n_str is the number


of strings in array str[ ].

I need help with printing and calling a C program... PLZ HELP!!?
May be you can contact a C expert live at website like http://askexpert.info/ to help you code your assignment.


What does this mean line by line in C++?

struct employee *allocemp(const char *name,const char *id,int age,double salary){


struct employee


*emp=new struct employee;


emp-%26gt;name=strdup(name);


strcpy(emp-%26gt;id,id);


emp-%26gt;age=age;


emp-%26gt;salary=salary;


return emp;


}

What does this mean line by line in C++?
Function definition "allocemp" ... likely meant as short-hand for allocate employee.





Semi-Line-by-line :





(1) ALLOCEMP is called with two c-string arguments, NAME and ID, an integral AGE, and a double floating point SALARY.





(2) Space for a new employee struct is allocated from the heap and a pointer stored in the local variable EMP (an employee struct pointer).





(3) Member variables of the newly allocated employee are then assigned per the data sent as arguments to this function ... c-strings are duplicated, as they are reference types.





(4) The value in EMP (a pointer to the new employee struct) is returned to the calling code.








So basically it's just allocating and initializing a new employee structure.


How should i used the searchpath parameter in C?

the syntax is


char *searchpath(const char *file);


now in this what comes in between the brackets. what is const char *file and how to get the value or how will it return.

How should i used the searchpath parameter in C?
i didn't got it well but to search for a file by its extension just write down in the search title *.file extension for example *.exe or *.doc


In C#, how do you declare a constant such that it can be used in a different class?

namespace abc


{


public class abcData


{


public const string str = "xyz";


}


}





I want the constant str to be accessible from another file that is referencing the "abc" namespace with "using abc;". How do I do this?

In C#, how do you declare a constant such that it can be used in a different class?
According to Object Oriented Design, you really shouldn't expose class properties directly. The task you're trying to accomplish can be done by using accessors with no Set method, ie. in this way:





namespace abc


{


public class AbcData


{


private const string str = "xyz";





public string AbcString


{


get { return str; }


}


}





}





In this way, you're hiding str, and exposing it using the Get Accessor method.
Reply:If you declare the constant as static, such as





public const static string str = "xyz";





then you should be able to reference the constant in another file by using abcData.str (if you're already "using abc;").

survey for money

C++ Help Please!?

Hello, I am trying to run this class, but when I compile, it is telling me that "cout" and "endl" are undeclared integers....? I obviously just want the results to be output, but what do I have to do to fix this? Any help is appreciated.





class Rectangle


{


public:


Rectangle()


{


height= 0;


width = 0;


}





Rectangle(double h, double w)


{


height = h;


width = w;


}





double getHeight() // retrive the height to print in main


{


return height;


}





double getWidth() // retrive the width to print in main


{


return width;


}





double getArea()const


{


return height * width;


}





double getPerimeter()


{


return ((height * 2) + (width * 2));


}





private:


double height;


double width;


};





int main()


{


Rectangle rectangle1(5,50);


Rectangle rectangle2(3.5,35.9);





cout %26lt;%26lt; rectangle1.getArea() %26lt;%26lt; endl;


cout %26lt;%26lt; rectangle1.getPerimeter() %26lt;%26lt; endl;


cout %26lt;%26lt; rectangle2.getArea() %26lt;%26lt; endl;


cout %26lt;%26lt; rectangle2.getPerimeter() %26lt;%26lt; endl;





return 0;


}

C++ Help Please!?
Just add the following two lines at the start





#include %26lt;iostream%26gt;


using namespace std;
Reply:#include %26lt;iostream%26gt;


using std::cout;


using std::endl;








or, just


#include %26lt;iostream%26gt;


//and you have to use the namespace in your code.





std::cout%26lt;%26lt; blah %26lt;%26lt; cout::endl;


C++ Data Types?

Lets say I want to do something like this:





#include %26lt;cstdlib%26gt;


#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;


#include %26lt;sstream%26gt;


#include %26lt;string%26gt;





const char *ip





int main(int argc, char *argv[])


{





std::cin %26gt;%26gt; ip





system("telnet" + ip);





}





what would the variable type of 'ip' have to be for this to work, and if it has to be converted from a certain type, how would I go about doing so?

C++ Data Types?
If you want to use direct string additions etc it would be better to use std::string and then convert it to character point for the system call as it wont support the string type





Here is the equivalent code








#include %26lt;cstdlib%26gt;


#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





int main(int argc, char *argv[])


{


std::string ip;


std::cin %26gt;%26gt; ip;





ip = "telnet "+ip;


system(ip.c_str());





}








Run the program and enter the ip address


$a.out


127.0.0.1


Trying 127.0.0.1...


Connected to 127.0.0.1 (127.0.0.1).


Escape character is '^]'.


login: ^[[A^D


Password:
Reply:There isn't any variable type for ip because it has more than 1 dot. Try using 4 variables and concatenating them system("telnet" + ip1 + "." + ip2 + "." + ip3 + "." + ip4) and integer should be ok.


You could also use a char array.


C++ beginner help plz?

const int size = 1000;


int sortarray[size];


int key = 0, j = 0;





int main(){





srand(time(0));


for(int i = 0; i %26lt; size; i++){ // starts the for loop


sortarray[i] = (rand()%10000) + 1; // makes numbers between 1 through 20 %/returns remainder


cout%26lt;%26lt;sortarray[i]%26lt;%26lt;" , ";


}





for(int i = 0; i %26lt; size; i++){ // starts the bubble sort


for(int j = size - 1; j %26gt; i; j--){ // starts the comparisons at the end of the array


if(sortarray [j] %26lt; sortarray[j - 1]){ // checks the current element with the previous one


key = sortarray[j]; // switches the elements if the conditions are met


sortarray[j] = sortarray[j - 1];


sortarray[j - 1] = key;


}


}


}





// formats the output prints to screen


cout%26lt;%26lt;endl%26lt;%26lt;endl;





for(int i = 0; i %26lt; size; i++){ // prints the sorted array





cout%26lt;%26lt;sortarray[i]%26lt;%26lt;", ";


}


return 0;


}


I wrote this code for bubble sort. How do I add a third array to fit the requirements of exchange sort method?

C++ beginner help plz?
Your code for bubble sort looks correct, but your question is confusing. Bubble sort is an exchange sort. Exchange sort is a general class of sorting algorithms, where the sort is executed by exchanging or swapping list elements.





I don't know what you mean by a third array (as you only have 1 array so far, the one to sort).
Reply:I suggest you to join C/C++ programming groups in yahoo for your programming doubts...


C++ follow up...?

After spending some more time with this, the code now works. I would like some help in coding the error statement.


1) If the user enters an age, say below 1 or exceeding 120, the user shd get an error message "Warning, age must be between 1 and 120" hence(!(1%26lt;=ageValue%26amp;%26amp;ageValue%26lt;=120)), and then the user must be prompted again to enter a valid age.


2) If the user enters a non-int value, the message is "Error: invalid entry" and prgm exits the loop. Where would be best to input these two messages? THANKS!





/ reading values printing out input in reverse


//************************************...





#include%26lt;iostream%26gt;


using namespace std;


const int MAX=1000;








int main()


{





int ageValue[MAX];


int count=0;


char choice;





cout%26lt;%26lt;"Enter the age of the youngest family member:"%26lt;%26lt;endl;


cin%26gt;%26gt;ageValue[count];





cout%26lt;%26lt;"Are there any more family members?(Y for yes and N for no)"%26lt;%26lt;endl;


cin%26gt;%26gt;choice;





for(count=1; choice=='Y'||choice==

C++ follow up...?
I had to make some more changes to your code. I placed comments around the changes that I made.





#include%26lt;iostream%26gt;


using namespace std;


const int MAX=1000;


/* moved to here so all functions can use them */


int ageValue[MAX];


int count=0;








/* new function */


void inputAge()


{


cout%26lt;%26lt;"Enter the age of the youngest family member:"%26lt;%26lt;endl;


cin%26gt;%26gt;ageValue[count];





/* Error 2) */


if (!cin)


{


/* not exactly sure what you want done here. */


/* to exit program */


cout%26lt;%26lt;"Your other message!"


exit(1);





/* to only stop input, and then print the other values out


change the return value to a bool and return false */


/* return false; */


}


/* Error 1) */


else if (ageValue[count]%26lt;1||ageValue[count]%26gt;120)


{


cout%26lt;%26lt;"Your error message!"%26lt;%26lt;endl;


/* recall this method */


inputAge();


}


}








int main()


{





char choice;





/* call to new function */


inputAge();





cout%26lt;%26lt;"Are there any more family members?(Y for yes and N for no)"%26lt;%26lt;endl;


cin%26gt;%26gt;choice;








/* Placed in the below while instad of the for.*/


while (choice=='Y'||choice=='y')


/*for(count=1; choice=='Y'||choice=='y'; count++)*/


{


/* Added the count increment here */


count++;





/* call to new function */


inputAge();





cout%26lt;%26lt;"Are there any more family members?(Y for yes and N for no)";


cin%26gt;%26gt;choice;


}








cout%26lt;%26lt;"Thank you. The ages of your family in reverse order are:"%26lt;%26lt;endl;


/* Change the count%26gt;0 to count%26gt;=0 for it to print out the first entry as well */


while(count%26gt;=0)


{


cout%26lt;%26lt;" "%26lt;%26lt;ageValue[count];





/* Place the count decrement here */


count--;


}





return 0;





}
Reply:I have not had a chance to compile this, so I am not sure it is error-free. But I think that it should work fine.








#include%26lt;iostream%26gt;


using namespace std;


const int MAX=1000;


int IsInRange(float); //returns 1 if argument is in range.








int main()


{





int ageValue[MAX];


int count=0;


char choice;


float temp;





cout%26lt;%26lt;"Enter the age of the youngest family member:"%26lt;%26lt;endl;


cin%26gt;%26gt;temp;





while(!(IsInRange(temp))


{


cout%26lt;%26lt;"Age must be whole number between 1 and 120!"%26lt;%26lt;endl%26lt;%26lt;"Try again: ";


cin%26gt;%26gt;temp;


}


ageValue[count] = (int)temp;





cout%26lt;%26lt;"Are there any more family members?(Y for yes and N for no)"%26lt;%26lt;endl;


cin%26gt;%26gt;choice;





for(count=1; choice=='Y'||choice=='y'; count++)


{


cout%26lt;%26lt;"Enter the age of the next youngest person"%26lt;%26lt;endl;


cin%26gt;%26gt;temp;





while(!(IsInRange(temp))


{


cout%26lt;%26lt;"Age must be between 1 and 120!"%26lt;%26lt;endl%26lt;%26lt;"Try again: ";


cin%26gt;%26gt;temp;


}


ageValue[count] = (int)temp;





cout%26lt;%26lt;"Are there any more family members?(Y for yes and N for no)";


cin%26gt;%26gt;choice;


}








cout%26lt;%26lt;"Thank you. The ages of your family in reverse order are:"%26lt;%26lt;endl;


while(count%26gt;0)


{


count--;





cout%26lt;%26lt;" "%26lt;%26lt;ageValue[count];


}





return 0;





}











int IsInRange(float);


{





if(1%26lt;temp||temp%26gt;=120) return (0);


for(int i = 1;i%26lt;=119;i++)


{


if(i%26lt;temp%26amp;%26amp;temp%26lt;(i+1))


return(0);


else return(1);


}


}
Reply:Looking at your account, it is looks like you don't go back to your questions to award points, so why should we give you the answer?

survey questions

C++ programming help!?!?

Anyways I can't get the 7th option for my menu to work.


Since, i don't know any other way to do this, i'm gonna post the program in parts....





#include "stdafx.h"


#include %26lt;iostream.h%26gt;


#include %26lt;iomanip.h%26gt;





int bank_menu(void);





const int SIZE=40;





struct


{


int cust_num;


int ssn;


char cust_name[SIZE];


float balance;


int act_type; //1=Checking; 2=Savings


}bank[10];





int main(int argc, char* argv[])





{


int choice;


int cust_index = -1;


do


{


choice = bank_menu();


if (choice == 1)


{


cout%26lt;%26lt;"You have chosen Load Customer into Structure.\n";


if (cust_index == 9)


cout%26lt;%26lt;"The structure is full.\n";


else


{


cust_index++;


bank[cust_index].cust_num = cust_index + 1;





cout%26lt;%26lt;"Enter Social Security Number: ";


cin%26gt;%26gt;bank[cust_index].ssn;


while (bank[cust_index].ssn %26lt; 100000000 || bank[cust_index].ssn %26gt; 999999999)

C++ programming help!?!?
EDIT: I added more at your SHORTENED VERSION link:


http://answers.yahoo.com/question/index?...





----------


I think the problem might be here in the transfer section:





cin%26gt;%26gt;transfer;


int c_index;


int s_index;


int i;


for (i=0; i%26lt;cust_index+1; i++)


{


if (bank[i].ssn == SSN)


{


if (bank[i].act_type == 1)


{


i=c_index;


}


else


{


i=s_index;


....


...





You have a loop for (i=0; i%26lt;cust_index+1; i++)


but you _might_ have not yet assigned a value to cust_index at the time you call the transfer section. Therefore, it's filled with whatever is in memory -- which may be a very, very large number -- and the loop travels on and on, incrementing 'i', until index i is completely off the array bank[] in:





if (bank[i].ssn == SSN)


...





...and the prog hangs/crashes ugly.





That's our 1st and main suspect. You can verify cust_index when calling the transfer section to be sure:





cout %26lt;%26lt; "cust_index is " %26lt;%26lt; cust_index;





...and thus ensure it's a "safe/small' value (and not negative!) before proceeding. Of course, this is just for debugging. You want to remove such stuff when you go final.








---- ----- ----- ----- -----





Loops are fequently the cause of program hang during run time, and it's hard to know if your code has hit some kind of lengthy or even infinite loop without visual indicators.





Optionally, when I'm debugging a tough problem and I need to inspect a loop variable, I might do something like this:





int iii= 20000;





while(iii--)


{


cout %26lt;%26lt; "\r iii is: " %26lt;%26lt; iii ;


///...other code here


}





This code will allow you to inspect the incrementor/decrementor "iii" as it clicks off without cluttering the screen full of numbers. The little "\r" keeps the cursor pinned to the start of the line.





Not only does this give you a strong visual clue, but the cout action allows you to CTR C keybreak out out of the loop easily if you can see the program is stuck in the loop. Much more amiable than calling taskmanager to kill a wayward execution, for example.





You can inspect all of the variables at run time in methods such as this til you pin down the culprit.


---





Use a standard comment by every piece of debug code so you can easily remove it all once fixed:





while(iii--)


{


cout %26lt;%26lt; "\r iii is: " %26lt;%26lt; iii ; //DEBUG ONLY





Then just do a find on string "DEBUG ONLY" for fast clean up.
Reply:You got to be kidding.


Sorry to be mean, but nobody here is going to debug your entire program - which is what you're asking.





Narrow down the problem and ask more specific question.
Reply:Set a break point at the beginning of the 7th choice and single step throught the code, watch the values of the variables. Since the program is crashing there, you are probably trying access memory that isn't valid (e.g. index problem) or something similar.


C++ program?

I have to write a program that will read from a file and store it in an array. whenever i run the program however, it doesn't output the numbers that are in the file. please tell me what i'm doing wrong. Here's my code:





#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;


using namespace std;





int main()


{


const int ARRAY_SIZE = 10;


int numbers[ARRAY_SIZE];


int count;


ifstream inputFile;





inputFile.open("numbers.txt");





for (count = 0; count %26lt; ARRAY_SIZE; count++)


inputFile %26gt;%26gt; numbers[count];





inputFile.close();





cout %26lt;%26lt; "The numbers are: ";


for (count = 0; count %26lt; ARRAY_SIZE; count++)


cout %26lt;%26lt; numbers[count] %26lt;%26lt; " ";


cout %26lt;%26lt; endl;


return 0;


}

C++ program?
Is "numbers.txt" in the same directory as your executable? For example in Visual Studio; projectfolder/DEBUG/ or /RELEASE/.
Reply:shouldn't it be numbers[count] %26gt;%26gt;inputfile;


C++ help... Due tomorrow.?

I need this program to work by tomorrow morning, but I can't tell that I'm doing anything wrong!!





Errors:


o_assignment5.cpp: In function `int main()':


o_assignment5.cpp:48: non-lvalue in assignment


o_assignment5.cpp:48: parse error before `-' token


o_assignment5.cpp:52: parse error before `)' token


o_assignment5.cpp:54: parse error before `)' token


o_assignment5.cpp: At global scope:


o_assignment5.cpp:61: parse error before `;' token


o_assignment5.cpp:61: syntax error before `++' token


o_assignment5.cpp:63: parse error before `;' token


o_assignment5.cpp:63: syntax error before `++' token


o_assignment5.cpp:66: syntax error before `%26lt;%26lt;' token


o_assignment5.cpp:70: syntax error before `.' token








Code:


#include %26lt;iostream%26gt;


#include %26lt;cstdlib%26gt;


#include %26lt;fstream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;cmath%26gt;





using namespace std;





const int SIZE = 15;


int colRow[SIZE][SIZE];


int userRow; // what the user of the program inputs for table width


int finalRow;


int userCol;

C++ help... Due tomorrow.?
The userRow - 1 = finalRow is not correct. I think that you mean: finalRow = userRow -1 and finalCol = userCol - 1





Try that it should compile.





But also I don't understand your loop code





the "int finalRow" will override the previously defined "finalRow" for the scope of the loop and likewise for the "int finalCol" loop.





HTH
Reply:userRow - 1 = finalRow


userCol - 1 = finalCol





Switch to


finalRow = userRow - 1


finalCol = userCol - 1
Reply:1. Look at your assignments for userRow and userCol from finalRow and finalCol





2. Your last loop isn't going to do what you intend it to.





Good luck.
Reply:1. You redeclared "outs" inside of main() ...don't do that.





2. Look at the following two lines:


userRow - 1 = finalRow // to get right number in array: rows


userCol - 1 = finalCol // to get right number in array: cols





You must place the variable to which a value is assigned in the LEFT side of the expression, like this: y = x - 1





3. One of your for() loops had a missing closing brace. Use proper indentation to find where this occurred.


C++ update....?

I finally figured that sub-code out(with some hints from others)..For those who do not know, this is a simple way to read an input file containing scores for 3 exams(in this case, of 6 students), and output the highest in each exam...








//Sample Program 12- A non-interactive program to calculate student grades.


//************************************...


#include%26lt;iostream%26gt;


#include%26lt;iomanip%26gt;


#include%26lt;fstream%26gt;


#include%26lt;string%26gt;


using namespace std;





const int SIZE=6;


int GetHighValue(int array[]);





int main()


{


int exam1Array[SIZE];


int exam2Array[SIZE];


int exam3Array[SIZE];


int i=0;


string name;


ifstream inFile;





inFile.open("grades.dat");


if(!inFile)


{


cout%26lt;%26lt;"Unable to open input file, program abnormally ended";


return 1;


}


for(i=0; i%26lt;SIZE; i++)


{





inFile%26gt;%26gt;name%26gt;%26gt;exam1Array[i]%26gt;%26gt;exam2Array[...





}








GetHighValue(exam1Array);


cout%26lt;%26lt;"The highest for exam 1 is"%26lt;%26lt;GetHighValue(exam1Array)%26lt;%26lt;endl;


GetHighValue(exam2Array);


cout%26lt;%26lt;"The highest for exam 2 is"%26lt;%26lt;GetHighValue(exam2Array)%26lt;%26lt;endl;


GetHighValue(exam3Array);


cout%26lt;%26lt;"The highest for exam 3 is"%26lt;%26lt;GetHighValue(exam3Array)%26lt;%26lt;endl;

















return 0;


}











int GetHighValue(/*in*/ int array[])


{


int highScore=0;


int i=0;





for(i=0; i%26lt;SIZE; i++)


{


if(array[i]%26gt;highScore)


highScore=array[i];


}





return highScore;


}

C++ update....?
You might want to retry the example code using STL library. It is amazing how easy it is to write over 60% of the code using C++ standard libraries.


It might not be so obvious in this small example, but as you move to bigger projects, you will see the benefit first hand.
Reply:sorry, i don't know, but you can try this site

surveys

C++ Program?

I'm having a problem with my assignment. I can't get the program to do what it's suppose to do. Here is the thing I'm suppose to make.





Suppose you have a group of people who need to be transported on buses and vans. You can chargter a bus only if you can fill it. Each bus holds 50 people. You must provide enough vans for the 49 or fewer people who will be left over after you charter buses. Whrite a programthat accepts a number of people left over that must be placed on vans.





I can't get the modulus operator to work.





Here is what I have done so far:





//Project.cpp


#include %26lt;iostream.h%26gt;


#include %26lt;stdlib.h%26gt;


main()


{


const int size=50; //Declare size as a constant


int number_of_people;


int total;


int r;


//Total number of people


cout %26lt;%26lt; "What is the total number of people";


cin %26gt;%26gt; number_of_people;


total=number_of_people/size;


r=number_of_people%size;


cout %26lt;%26lt;"The total number of buses is ...

C++ Program?
1st the code is not complete


and i want to know what is the use of r


if r is the number of buses then u must use the divide sign"/" not the moduls sign "%"


if u r using r as the number of people remaning


then it must be in the form


r=number_of_people-(total*size);


note:the above line will give the right nswer because u r using int for total na dint for size, but if u use float it will not work and r will be zero


i hope this have solved ur problem
Reply:It's all good.





'total ' is the number of buses.


'r' is the number of poeple left who must go in vans.





Sample: 190 people = 3 busses (150 people) and 190%50 is 40 (same as 190-150 which you would expect).
Reply:Did you add ( } ) mark for your maiin() frame?
Reply:replace the line:


int total;


with this line:


float total;





the reason is that you can not store a float value in an integer which is what you are doing here:


total=number_of_people/size;


C++ modify program?

i need it to stop when uncut=total my orginal prog. is





#include%26lt;cmath%26gt;


#include%26lt;string%26gt;


#include%26lt;iostream%26gt;





using namespace std;





int main()


{





double total, uncut;


const double restrate=.02;





total = 14000;


uncut = 2500;





cout %26lt;%26lt; "Year..............Acres" %26lt;%26lt; endl %26lt;%26lt; endl;





for(int k=0; k%26lt;20; k++)


{


cout %26lt;%26lt; k+1 %26lt;%26lt; ".............." %26lt;%26lt; uncut %26lt;%26lt; endl;





uncut += restrate * uncut;


}





getchar();





return 0;


}

C++ modify program?
add this line after uncut += restrate * uncut;





if (uncut==total) return 0;
Reply:if(uncut==total) break;


C++ Help Pllllease!!?

Hello, now for this class, I have to add accessor and mutator functions for all the data fields, but I have no idea how... any help is appreciated!!!





#include %26lt;iostream%26gt;


using namespace std;





class Rectangle


{


public:


Rectangle()


{


height= 0;


width = 0;


}





Rectangle(double h, double w)


{


height = h;


width = w;


}





double getHeight() // retrive the height to print in main


{


return height;


}





double getWidth() // retrive the width to print in main


{


return width;


}





double getArea()const


{


return height * width;


}





double getPerimeter()


{


return ((height * 2) + (width * 2));


}





private:


double height;


double width;


};





int main()


{


Rectangle rectangle1(4,40);


Rectangle rectangle2(3.5,35.9);





cout %26lt;%26lt;"The area of Rectangle 1 is: " %26lt;%26lt; rectangle1.getArea() %26lt;%26lt; endl;


cout %26lt;%26lt;"The perimeter of Rectangle 1 is: " %26lt;%26lt; rectangle1.getPerimeter() %26lt;%26lt; endl;


cout %26lt;%26lt;"The area of Rectangle 2 is: " %26lt;%26lt; rectangle2.getArea() %26lt;%26lt; endl;


cout %26lt;%26lt;"The perimeter of Rectangle 2 is: " %26lt;%26lt; rectangle2.getPerimeter()

C++ Help Pllllease!!?
You can use mutators with the following prototype





void setHeight(double h);


void setWidth(double w);





Here are the code changes required





#include %26lt;iostream%26gt;


using namespace std;





class Rectangle


{


public:


Rectangle()


{


height= 0;


width = 0;


}





Rectangle(double h, double w)


{


height = h;


width = w;


}





double getHeight() // retrive the height to print in main


{


return height;


}





double getWidth() // retrive the width to print in main


{


return width;


}





/////////////////////////////////////...


void setHeight(double h) // set the height -- mutator


{


height = h;


}





void setWidth(double w) // set the width -- mutator


{


width = w;


}


/////////////////////////////////////...








double getArea()const


{


return height * width;


}





double getPerimeter()


{


return ((height * 2) + (width * 2));


}





private:


double height;


double width;


};





int main()


{


Rectangle rectangle1(4,40);


Rectangle rectangle2(3.5,35.9);





cout %26lt;%26lt;"The area of Rectangle 1 is: " %26lt;%26lt; rectangle1.getArea() %26lt;%26lt; endl;


cout %26lt;%26lt;"The perimeter of Rectangle 1 is: " %26lt;%26lt; rectangle1.getPerimeter() %26lt;%26lt; endl;


cout %26lt;%26lt;"The area of Rectangle 2 is: " %26lt;%26lt; rectangle2.getArea() %26lt;%26lt; endl;


cout %26lt;%26lt;"The perimeter of Rectangle 2 is: " %26lt;%26lt; rectangle2.getPerimeter();





/////////////////////////////////////...


// setting new values to rectangle 2


rectangle2.setHeight(5.55);


rectangle2.setWidth(1.11);





cout%26lt;%26lt;"\n AREA WITH NEW VALUES "%26lt;%26lt;endl;


cout %26lt;%26lt;"The area of Rectangle 2 is: " %26lt;%26lt; rectangle2.getArea() %26lt;%26lt; endl;


cout %26lt;%26lt;"The perimeter of Rectangle 2 is: " %26lt;%26lt; rectangle2.getPerimeter();





/////////////////////////////////////...





}
Reply:Accessors are your get functions (getHeight, getWidth). They provide access to the private variables in your class. You already have those.





What your class doesn't have is the mutators which are set functions (setHeight, setWidth). They need to take in a double parameter and make the private variable (eg. private double height) equal to that parameter.





Hope that gives you some clues.


C++ Help Please!?

Ok guys. What I have to do is write an array that reads 10 numbers and displays how many are divisible by three. I wrote the code, but what I don't understand is that is always outputs 1 less then what the answer should be. What do I need to do to fix it? This is code I have made so far:





#include %26lt;iostream%26gt;


using namespace std;





int main()


{


const int TOTALNUMBERS = 10;


int numbers[TOTALNUMBERS];





// Read all numbers


for (int i = 0; i %26lt; TOTALNUMBERS; i++)


{


cout %26lt;%26lt; "Enter a number: ";


cin %26gt;%26gt; numbers[i];


}


// Find numbers divisible by 3


int div = numbers[0];


for (int i = 0; i %26lt; TOTALNUMBERS; i++)





if (div / 3)


div = numbers[i];








cout %26lt;%26lt; "Numbers divisible by three: " %26lt;%26lt; div %26lt;%26lt;endl;





return 0;





}








Thanks!

C++ Help Please!?
Got a little logic error going on... You're OK up to the find numbers portion.








// Find numbers divisible by 3


int div =0; /* CHANGED; just to keep track of them */





/* Added brackets */


for (int i = 0; i %26lt; TOTALNUMBERS; i++) {


/*Use the MOD operator. This will yield the remainder of the division */


if ((numbers[i]% 3)==0)


div ++;


}


cout %26lt;%26lt; "Numbers divisible by three: " %26lt;%26lt; div %26lt;%26lt;endl;





return 0;





}








P.S. Your FOR condition is fine!

survey monkey

C++ Help! This is juat a small part of my program so it's very raw. I want the prgm to read an input file ....

//Sample Program 12- A non-interactive program to calculate student grades.


//************************************...





#include%26lt;iostream%26gt;


#include%26lt;iomanip%26gt;


#include%26lt;fstream%26gt;


#include%26lt;cstring%26gt;


using namespace std;





const int SIZE=20;





int main()


{


int exam1Array[SIZE];


int exam2Array[SIZE];


int exam3Array[SIZE];


int highScore;


int count=0;


string name[SIZE];


ifstream inFile;





inFile.open("grades.dat");


if(!inFile)


{


cout%26lt;%26lt;"Unable to open input file, program abnormally ended";


return 1;


}





inFile%26gt;%26gt;name[count]%26gt;%26gt;exam1Array[count]%26gt;%26gt;...


highScore=0;


for(count=0; count%26lt;SIZE; count++)





if(array[count]%26gt;highScore)


highScore=array[count];








cout%26lt;%26lt;highScore%26lt;%26lt;endl;


return 0;


}

C++ Help! This is juat a small part of my program so it's very raw. I want the prgm to read an input file ....
in your loop, you forgot the brackets. change:





for(count=0; count%26lt;SIZE; count++)





if(array[count]%26gt;highScore)


highScore=array[count];





cout%26lt;%26lt;highScore%26lt;%26lt;endl;


return 0;





to





for(count=0; count%26lt;SIZE; count++)


{


if(array[count]%26gt;highScore)


{


highScore=array[count];


cout%26lt;%26lt;highScore%26lt;%26lt;endl;


}


}


return 0;
Reply:Are you really supposed to go online to get others to do your assignments for you?
Reply:The following code will work in VC++ 2005:


[Create a new Win32 Console Project]





#include "stdafx.h"


const int SIZE=20;





int _tmain(int argc, _TCHAR* argv[])


{


float exam1Array[SIZE];


float highScore = 0.0;


int count=0;


int error;


FILE * inFile;





fopen_s(%26amp;inFile,"c:\\temp\\junk\\grades....


if(feof(inFile))


{


printf("Unable to open input file, program abnormally ended");


return 1;


}





fseek(inFile, 0L, SEEK_SET );


while (!feof(inFile))


{


error = fscanf_s(inFile,"%f",%26amp;exam1Array[count])...


if (exam1Array[count] %26gt; highScore)


highScore = exam1Array[count];


count++;


}





fclose(inFile);


printf("Highest Score is = %f",highScore);


getchar();


return 0;


}





The grades.dat file should look like:





53.5


84.2


98.1





with no Carriage return after the last grade.


This is something you can play with in the mean time. Happy learning! Remember to give me points for this...
Reply:buy K%26amp;R book on C called "The C Programming Language, Second Edition".. it has all this easy stuff in it... if you are starting with C .. you should really have this book... it is the basis of all C


C++ comp programming...basic question?

what is wrong here:





class CC


{ public;


void set(int, int);


void print () const;


CC () ;


CC (int, int);


bool CC (int, int);


private:


int u;


int v;


};

C++ comp programming...basic question?
This is a easy one.


Constructors can't have return types.





bool CC (int, int);


CC can't return bool.
Reply:It's useful to learn what your compiler errors mean, and where to look, debugging is one of the most useful skills.





Use a search engine to find what the error your compiler is giving you means, and see if you can work it out from there. It will make programming a whole lot easier in the long run. Of course, ask here as a last resort by all mean.





Looks like a typo, you put the colon after private, but obviously missed shift when typing it after public





public;





should be





public:
Reply:You need a : after public.





class CC


{


public:





void set(int, int);


C++ need help changing a prog.?

this is my current program i need to change it so i can input the years.





#include%26lt;cmath%26gt;


#include%26lt;string%26gt;


#include%26lt;iostream%26gt;





using namespace std;





int main()


{





double total, uncut;


const double restrate=.02;





total = 14000;


uncut = 2500;





cout %26lt;%26lt; "Year..............Acres" %26lt;%26lt; endl %26lt;%26lt; endl;





for(int k=0; k%26lt;20; k++)


{


cout %26lt;%26lt; k+1 %26lt;%26lt; ".............." %26lt;%26lt; uncut %26lt;%26lt; endl;





uncut += restrate * uncut;


}





getchar();





return 0;


}

C++ need help changing a prog.?
Prompt the user to inpu the data u want. cout out a statement asking to input the data then use cin to get the input.





To do this u need to type





cin%26gt;%26gt;"data";





after prompting the input


this will set ur input data to equal the variable for the data. Put this in the input section of your program. You would do it like this, lets call the new variable "data":





#include%26lt;cmath%26gt;


#include%26lt;string%26gt;


#include%26lt;iostream%26gt;





using namespace std;





int main()


{





double total, uncut;


const double restrate=.02;


double data=0;





total = 14000;


uncut = 2500;





cout%26lt;%26lt;"Input the data needed"%26lt;%26lt;endl; //this will promt the data to be entered


cin%26gt;%26gt;data; //this will recive the data





cout %26lt;%26lt; "Year..............Acres" %26lt;%26lt; endl %26lt;%26lt; endl;





for(int k=0; k%26lt;20; k++)


{


cout %26lt;%26lt; k+1 %26lt;%26lt; ".............." %26lt;%26lt; uncut %26lt;%26lt; endl;





uncut += restrate * uncut;


}





getchar();





return 0;


}


C++ Help! Why is the identifier undeclared?

Ok... I have this code that I wrote that takes 10 numbers and outputs the amount divisible by 3, but the one and only error message reads that 'i' in line 18 is an undeclared integer. What do I need to do to fix this? Here's the code. Thanks guys.





#include %26lt;iostream%26gt;


using namespace std;





int main()


{


const int TOTALNUMBERS = 10;


int numbers[TOTALNUMBERS];





// Read all numbers


for (int i = 0; i %26lt; TOTALNUMBERS; i++)


{


cout %26lt;%26lt; "Enter a number: ";


cin %26gt;%26gt; numbers[i];


}


//Find numbers divisible by 3


int div = 0;


for (int i = 0; i %26lt; TOTALNUMBERS; i++);


{


if ((numbers[i] % 3)==0)


div++;


}


cout %26lt;%26lt; "Numbers divisible by three: " %26lt;%26lt; div %26lt;%26lt;endl;





return 0;





}

C++ Help! Why is the identifier undeclared?
You have a semicolon at the end of the for statement. This 'closes' the for loop and its associated 'i' is dropped.
Reply:It might be that since you already declared i in the other for loop, try taking off the int.


for( i=0;





I see nothing else
Reply:It is a semi-colon at the end of your loop that should not be there.
Reply:for (int i = 0; i %26lt; TOTALNUMBERS; i++);





theres a semicolon at end of second for loop where there shouldn't be one

online survey

C++ help ?

#include %26lt;iostream%26gt;


using namespace std;


class SimpleCat


{public:


SimpleCat(int age, int weight);


SimpleCat(SimpleCat %26amp;);


~SimpleCat();


int getAge()const {return itsAge;}


void setAge(int ager) {itsAge = ager;}


void setWeight(int weighter) {itsAge = weighter;}


private:


int itsAge;


int itsWeight;};


SimpleCat::SimpleCat(int age, int weight)


{itsAge = age;


itsWeight = weight;}


SimpleCat::SimpleCat(SimpleCat %26amp;)


{cout %26lt;%26lt; "SimpleCat Copy Constructor\n";}


SimpleCat %26amp; FunctionOne(SimpleCat%26amp; theCat);


int main(){cout %26lt;%26lt; "Making a Cat\n";


SimpleCat Frisky(5,10);


cout %26lt;%26lt; "Inside Main.Frisky is " %26lt;%26lt; Frisky.getAge() %26lt;%26lt; " years old.\n"%26lt;%26lt; "Passing Frisky into FunctionOne\n";


FunctionOne(Frisky);


cout %26lt;%26lt; "Inside Main.Frisky is " %26lt;%26lt; Frisky.getAge() %26lt;%26lt; " years old.\n" %26lt;%26lt; "Passing Frisky into FunctionOne\n";


system("PAUSE");}


SimpleCat %26amp; FunctionOne(SimpleCat %26amp; theCat){


cout %26lt;%26lt; "Inside Function One\n" %26lt;%26lt; "Setting Frisky Age=10 %26amp; Weight=60\n";


theCat.setAge(10);


return(theCat);}

C++ help ?
I don't see "new" in your code, but the new operator provides dynamic storage/memory allocation.





I'm curious, what did you change to get it to compile? Thanx...


C++ Help Please!?

Ok so I had to find the smallest number in a 10-number array and I did that with this.





#include %26lt;iostream%26gt;


using namespace std;





int main()


{


const int TOTALNUMBERS = 10;


int numbers[TOTALNUMBERS];





// Read all numbers


for (int i = 0; i %26lt; TOTALNUMBERS; i++)


{


cout %26lt;%26lt; "Enter a number: ";


cin %26gt;%26gt; numbers[i];


}


// Find the smallest


int min = numbers[0];


for (int i = 1; i %26lt; TOTALNUMBERS; i++)


{


if (min %26gt; numbers[i])


min = numbers[i];


}





cout %26lt;%26lt; "The smallest number is " %26lt;%26lt; min %26lt;%26lt;endl;





return 0;


}





But now I have to find the index of the smallest number, and I have no idea of how to do that. Any tips? Thanks alot guys.

C++ Help Please!?
see for the additions i have made:





#include %26lt;iostream%26gt;


using namespace std;





int main()


{


const int TOTALNUMBERS = 10;


int numbers[TOTALNUMBERS],location;





// Read all numbers


for (int i = 0; i %26lt; TOTALNUMBERS; i++)


{


cout %26lt;%26lt; "Enter a number: ";


cin %26gt;%26gt; numbers[i];


}


// Find the smallest


int min = numbers[0];


location=0;


for (int i = 1; i %26lt; TOTALNUMBERS; i++)


{


if (min %26gt; numbers[i])


{min = numbers[i]; location=i;}


}





cout %26lt;%26lt; "The smallest number is " %26lt;%26lt; min %26lt;%26lt;" at location "%26lt;%26lt;location+1%26lt;%26lt;endl;





return 0;


}
Reply:I would set up a for loop like for(int i = 0; i %26lt; 10; i++) and a variable called "smallestIndex" = 0 which would loop through the array and test the numbers[i] with the current smallest indexand


if(numbers[i] %26lt; numbers[smallestIndex]);


smallestIndex = i;
Reply:Seeing that this is probably a homework assignment, I'll describe what you need to do:





Create an extra variable (near //Find the smallest) to hold the index.





Then, inside the loop, when you are trying to find the smallest index, not only copy the value of the smallest value (min=numbers[i]), but also its index. Store it in the variable you created.





Finally, in your cout statement, print the value of this variable.


..........C++ code?

How would I get it to do display the following patterns using the FOR statement?








*********


********


*******


******


so on…





*********


********


*******


******


so on…





Such as:


*


**


***


****


*****


so on…





I have tried using the WHILE for several hours. Unknowing I had to use the FOR all along.





#include %26lt;iostream%26gt;





using std::cout;


using std::cin;


using std::endl;





[code]


int main()


{


//declare variables


const char asterk = '*';


int a = 9;


int b = 0;





while (a %26gt; 0)


{


b = a;


while (b %26gt; 0)


{


cout %26lt;%26lt; asterk;


b = b - 1;


}


a = a - 1;


cout %26lt;%26lt; endl;


}


//end while





return 0;


} //end of main function

..........C++ code?
//Decreasing


int main()


{


//declare variables


const char asterk = '*';


int a = 0;


int b = 0;





For(a = 9;a %26gt; 0 ; a--)


{


For(b=a;b %26gt; 0 ; b--)


{


cout %26lt;%26lt; asterk;


}


cout %26lt;%26lt; endl;


}


//end while





return 0;


} //end of main function





//Increasing


int main()


{


//declare variables


const char asterk = '*';


int a = 0;


int b = 0;





for(a = 1; a %26lt; 9;a++)


{


for(b = a; b %26gt; 0 ;b--)


{


cout %26lt;%26lt; asterk;


}


cout %26lt;%26lt; endl;


}


//end while





return 0;


} //end of main function
Reply:assume the max possible number of * on a line is n.





1) descreasing:





for(int i=n; i%26gt;0; i--)


for(int j=0; j%26lt;i; j++)


cout%26lt;%26lt;"*";


cout%26lt;%26lt;endln;





2) increasing:





for (int i=0; i%26lt;n; i++)


for (int j=0; j%26lt;i; j++)


cout%26lt;%26lt;"*";


cout%26lt;%26lt;endln;


What is wrong with this c++ program??

I am trying to get this program to work but i can't - I am very new to this





#include %26lt;iostream%26gt;





using namespace std;





int Main()


{


const int seconds_per_minute = 60;


const int minutesPerHour = 60;





int timeInSeconds; // time that is input -- totally in seconds


int hours; // how many hours in time


int minutes; // how many minutes in time


int seconds; // how many seconds in time





cout %26lt;%26lt; "Enter the time in seconds only: " %26lt;%26lt; endl;


cin %26gt;%26gt; timeInSeconds;





seconds = timeInSeconds % seconds_per_minute;


minutes = timeInSeconds / seconds_per_minute % minutesPerHour;


hours = timeInSeconds / seconds_per_minute * seconds_per_minute;


// check the values of seconds, minutes, and hours


return 0;


}

What is wrong with this c++ program??
It would be helpful to know the error if any this program is trying to generate. Obviously you are trying to get it to display the Values you have setup.





This is going to sound stupid, but the code looks fine with exception to the modulo calls. If your trying to use the remainder's for your values that might be where you are getting messed up (i.e. the % calls). If your trying to output your code definitely need to insert some cout's in there. This is pretty much all I can tell you from the pseudo code without knowing the error it generates. ALWAYS output your variables to see what is going on before committing it to a function.
Reply:First you need to check if they have inputted over 60 seconds(1 minute) so you can calculate minutes. Do the same for hour, and check to see if you have at least 60 minutes to calculate hrs.





after "cin%26gt;%26gt; timeInSeconds" it should be:





if(timeInSeconds%26gt;=60) then //check to see if you have atleast 60 seconds


{


minuteSoFar = timeInSeconds / seconds_per_minute;


//minuteSoFarwill give you the number of minutes so far


//before calculating hours.Also since it is integer it wont give


//you a decimal value..e.g 70/60 will give you 1 not 1.167.





seconds=timeInSeconds%seconds_per_minute


// left over amount from mins, which is the seconds





if(minutesSoFar%26gt;=60)//check to see you have at least 60mins(1hr)


{


hours= minuteSoFar/minutesPerHour;


minutes=minuteSoFar%minutesPerHour;


}


else


hours = 0;


}


else


{


hours = 0;


minutes = 0;


}





cout %26lt;%26lt; "Hours = " %26lt;%26lt; hours %26lt;%26lt;endl;


cout %26lt;%26lt; "Minutes = " %26lt;%26lt; minutes %26lt;%26lt;endl;


cout %26lt;%26lt; "Seconds =" %26lt;%26lt; seconds %26lt;%26lt;endl;


return 0;





i think that should be right
Reply:hours = timeInSeconds / seconds_per_minute * seconds_per_minute;





operations "/" and "*" has equal priority so they will be executed consequently, one after one: first, the time in seconds will be diveded by the number of seconds per minute ( i.e. we get number of minutes), then this result will be multiplied by the number of seconds per minute.
Reply:Well, for starters, 'Main' should be 'main'.

salary survey

C++ I only have one error, I have the closing bracket at the end so what is wrong? Error C1004?

#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


using namespace std;





const char Semi_colon = ';';





const string VERB1 = "guess";








int main ()


{





string firstLine;





int play;


int escape;





string guess;





int cl18=0; // make sure the semi-colon


int cl20=0; // make sure the semi-colon


string clue;





;int start=0;





start:


cout %26lt;%26lt; "This program was created by Amanda Harmony";


cout %26lt;%26lt; "Would you like to play?\n Press 1 for yes, and 0 for no.\n";


cin %26gt;%26gt; play;


if ( play == 1 )


{


goto cl1;


};


if ( play == 0 )


{


goto ender;


};








cl1:


cout %26lt;%26lt; "I am not real." %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if ( guess == "Star Trek" )


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";


cout %26lt;%26lt; "Guess again?";


cin %26gt;%26gt; guess;


firstLine = "Star Trek";





cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl1;





};





cl2:


cout %26lt;%26lt; "I take place in the future." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";


cout %26lt;%26lt; "Guess again?";


cin %26gt;%26gt; guess;


firstLine = "Star Trek";





cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl2;


};


cl3:


cout %26lt;%26lt; "There is a whole new generation of me." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";


cout %26lt;%26lt; "Guess again?";


cin %26gt;%26gt; guess;


firstLine = "Star Trek";





cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl3;


};


cl4:


cout %26lt;%26lt; "I take you to new places where no one has been before." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n ";


cout %26lt;%26lt; "Guess again?";


cin %26gt;%26gt; guess;


firstLine = "Star Trek";





cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl4;


};





cl5:


cout %26lt;%26lt; "I have a doctor with me at all times." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";


cout %26lt;%26lt; "Guess again?";





cin %26gt;%26gt; guess;


firstLine = "Star Trek";





cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl5;


};


cl6:


cout %26lt;%26lt; "Sometimes I can't believe my ears." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";


cout %26lt;%26lt; "Guess again?";


cin %26gt;%26gt; guess;


firstLine = "Star Trek";





cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl6;


};








cl7:


cout %26lt;%26lt; "I have been around since 1965." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";


cout %26lt;%26lt; "Guess again?";


cin %26gt;%26gt; guess;


firstLine = "Star Trek";





cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl7;


};








cl8:


cout %26lt;%26lt; "I am the story of a mission." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n ";


cout %26lt;%26lt; "Guess again?";





cin %26gt;%26gt; guess;


firstLine = "Star Trek";





cin %26gt;%26gt; escape;


if ( escape == 0 )


{





goto cl8;


};





cl9:


cout %26lt;%26lt; "I have been on TV and the movies." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n ";


cout %26lt;%26lt; "Guess again?";





cin %26gt;%26gt; guess;


firstLine = "Star Trek";





cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl9;


};


cl10:





cout %26lt;%26lt; "I see stars and planets scientists have never seen." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt;guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";


cout %26lt;%26lt; "Guess again?";





cin %26gt;%26gt; guess;


firstLine = "Star Trek";





cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl10;


};





cl11:





cout %26lt;%26lt; "I take about an hour at the time" %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n ";


cout %26lt;%26lt; "Guess again?";





cin %26gt;%26gt; guess;


firstLine = "Star Trek";





cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl11;


};


cl12:





cout %26lt;%26lt; "My ships don't travel by sea." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";


cout %26lt;%26lt; "Guess again?";





cin %26gt;%26gt; guess;


firstLine = "Star Trek";





cin %26gt;%26gt; escape;


if ( escape == 0 )





goto cl12;


};


cl13:


cout %26lt;%26lt; "I know asians, African-Americans and Russians." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";


cout %26lt;%26lt; "Guess again?";





cin %26gt;%26gt; guess;


firstLine = "Star Trek";





cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl13;


};


cl14:


cout %26lt;%26lt; "John Belshi and Dan Ackroyd made fun of me." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";


cout %26lt;%26lt; "Guess again?";





cin %26gt;%26gt; guess;


firstLine = "Star Trek";





cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl14;


};


cl15:





cout %26lt;%26lt; "Although not my business my interprise keeps me going." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n ";


cout %26lt;%26lt; "Guess again?";





cin %26gt;%26gt; guess;


firstLine = "Star Trek";





cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl15;


};


cl16:


cout %26lt;%26lt; "I like to keep my own space." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";


cout %26lt;%26lt; "Guess again?";





cin %26gt;%26gt; guess;


firstLine = "Star Trek";


{


cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl16;


};





cl17:


cout %26lt;%26lt; "I have a cult following." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n ";


cout %26lt;%26lt; "Guess again?";





cin %26gt;%26gt; guess;


firstLine = "Star Trek";


{


cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl17;


};





cl18: cout %26lt;%26lt; "Certain crystals empower me." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";


cout %26lt;%26lt; "Guess again?";





cin %26gt;%26gt; guess;


firstLine = "Star Trek";


{


cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl18;


};


cl19:





cout %26lt;%26lt; "A person names data resides on this ship." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


if (guess != "Star Trek")


{





cout %26lt;%26lt; "INCORRECT To guess, again press 1. To quit, press 0.\n";


cout %26lt;%26lt; "Guess again?";





cin %26gt;%26gt; guess;


firstLine = "Star Trek";


{


cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl9;


};





cl20:


cout %26lt;%26lt; "Kirk vs. Picard." %26lt;%26lt; endl;


cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;


cin %26gt;%26gt; guess;


if (guess == "Star Trek")


{


cout %26lt;%26lt; "CORRECT!";


}


if (guess != "Star Trek")


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";


cout %26lt;%26lt; "Guess again?";





cin %26gt;%26gt; guess;


firstLine = "Star Trek";


{


cin %26gt;%26gt; escape;


if ( escape == 0 )


{


goto cl20;


};








ender:


return 0;


}

C++ I only have one error, I have the closing bracket at the end so what is wrong? Error C1004?
I'm not sure why you are doing it with "GOTO". I have re-implemented it for you, and it works with one loop, much easier to understand. I compiled and ran it, I'm pretty sure it does what you want.





It creates a list of clues, and each incorrect guess provides you with a different clue. If you guess it correctly, it ends.





[CODE START]


#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


#include %26lt;vector%26gt;








using namespace std;





int main()


{


const string correctAnswer = "startrek";


const string guess = "Guess?";


int keepGoing;


string input;


//***


// Do we really want to play?


//***





cout %26lt;%26lt; "This program was created by Amanda Harmony";


cout %26lt;%26lt; "Would you like to play?\n Press 1 for yes, and 0 for no.\n";


cin %26gt;%26gt; keepGoing;


if (keepGoing == 0)


{


cout %26lt;%26lt; "Goodbye." %26lt;%26lt; endl;


return 0;


}





//***


// Establish our list of clues


// We should put this in a method but i'm being lazy.


//***


std::vector%26lt;string%26gt; clues;


string currentQ = "I am not real.";


clues.push_back(currentQ);


currentQ = "I take place in the future.";


clues.push_back(currentQ);


currentQ = "There is a whole new generation of me.";


clues.push_back(currentQ);


currentQ = "I take you to new places where no one has been before.";


clues.push_back(currentQ);


currentQ = "I have a doctor with me at all times.";


clues.push_back(currentQ);


currentQ = "Sometimes I can't believe my ears.";


clues.push_back(currentQ);


currentQ = "I have been around since 1965.";


clues.push_back(currentQ);


currentQ = "I am the story of a mission.";


clues.push_back(currentQ);


currentQ = "I have been on TV and the movies.";


clues.push_back(currentQ);


currentQ = "I see stars and planets scientists have never seen.";


clues.push_back(currentQ);


currentQ = "I take about an hour at the time";


clues.push_back(currentQ);


currentQ = "My ships don't travel by sea.";


clues.push_back(currentQ);


currentQ = "I know asians, African-Americans and Russians.";


clues.push_back(currentQ);


currentQ = "John Belshi and Dan Ackroyd made fun of me.";


clues.push_back(currentQ);


currentQ = "Although not my business my interprise keeps me going.";


clues.push_back(currentQ);


currentQ = "I like to keep my own space.";


clues.push_back(currentQ);


currentQ = "I have a cult following.";


clues.push_back(currentQ);


currentQ = "Certain crystals empower me.";


clues.push_back(currentQ);


currentQ = "A person names data resides on this ship.";


clues.push_back(currentQ);


currentQ = "Kirk vs. Picard.";


clues.push_back(currentQ);








for (int i=0; i %26lt; clues.size(); ++i) //let's go through all the clues


{


cout %26lt;%26lt; clues[i] %26lt;%26lt; endl;


cout %26lt;%26lt; guess %26lt;%26lt; endl;


cin %26gt;%26gt; input;





if (0 == input.compare(correctAnswer)) //star trek


{


cout %26lt;%26lt; "CORRECT!" %26lt;%26lt; endl;


return 0;


}


else


{


cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0." %26lt;%26lt; endl;


cin %26gt;%26gt; keepGoing;





if (keepGoing == 0)


{


return 0;


}


}





}





cout %26lt;%26lt; "Sorry, game over!" %26lt;%26lt; endl;


return 0;


}





[CODE END]
Reply:phew..


im glad im not taking that course..


OMGWTF..


im taking comp eng'g..


lol..


too bad just a freshmen..^^,


cant help..