>>when I compile, there are no errors,
Ditch the compiler and use a different one. There is a link error.
>>void print ()
Wrong. should be void testClass::print ()
>>when I compile, there are no errors,
Ditch the compiler and use a different one. There is a link error.
>>void print ()
Wrong. should be void testClass::print ()
which ones did you find??
1) Are you compiling for UNICODE?
2) what compiler
3) how is UPDATE_DIR declared
4) note that %s and %S are not the same thing. See this
You need two loops to do that. You have to check each number against all the previous values.
int a[10] = {5,6,7,8,9,10.11,12,13,1};
int i,j,isTrue;
isTrue = 1; // assume true
for(i = 0; i < 9 && isTrue == 1; i++)
{
for( j = i+1; j < 10; j++)
{
if( a[i] > a[j] )
{
isTrue = 0;
break;
}
}
read this. I'm not going to do your homework for you.
BTW there is no such thing as "%n" in scanf. The link I give you contains all the valid characters you can put after the % sign.
either fmod() or modf(), I'm not sure which one you want. Use google and look them up if you don't know what they do.
try this: compiled with vc++ 2008 express
#include <windows.h>
#include <iostream>
using std::cin;
int main()
{
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd,SW_MAXIMIZE);
cin.get();
return 0;
}
What problem are you having? You need to post the code you have tried. If you have not started yet, why not? Do the program in small steps -- do the first part first. When that is finished and tested, then move on to the second part.
You are passing vowel incorrectly. The & symbol is used in main to pass vowel by reference, then the * pointer is used in the actual function
void generate_random_vowel (char* vowel)
{
*vowel = 'a';
}
int main()
{
char vowel;
generate_random_vowel( &vowel );
}
in a loop, use % operator to get the last digit, then /= operator to shift digits right and drop the last digit.
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int x = 123;
string a;
while(x > 0)
{
int n = x%10;
x /= 10;
a += (char)(n + '0');
}
reverse(a.begin(),a.end());
cout << a << '\n';
return 0;
}
[edit]Or better still, use previously posted examples which use stringstream class. They are a lot simpler than what I posted here.
win32 api doesn't work on non-Windows platforms, but this code snippet will work with some possible mods to the defines at the top.
line 41: That is a horrible way to test for eof -- all you need is this:
while( getline(inputFile, line) )
{
cout << line << '\n';
}
lines 55-60: WTF??? You can not code nested while loops like that and expect anything other than the results you got.
while( inputFile >> name >> a >> age >> number)
{
// blabla
}
Check the OnTimer event handler, maybe there is something that causes the window to be repainted.
lines 74-80: you don't need to call strcmp() to compare two std::string objects -- just use their == operators if(type == normal)
Recode lines 98-105 similarily.
Also those if statements will give you a false validity result. Lets say the type is gold. The very first if statement about normal will set valid to false, which is incorrect. The way to do it is to have just one if statement that tests all of them at the same time
if( type != normal && type != silver && type != gold && type != plat)
valid = false;
void foo(const char* str)
{
// display the string contents here
}
int main()
{
foo("Once upon a time ...");
foo("there were three little pigs.");
// etc etc
}
y not? stdio.h is not used in c++ programs, only C programs. conio.h is not recommended because its no-standard and not supported by very many compilers.
stdio.h defines FILE structure and associated functions. This is for file read/write. In c++ programs we would use <fstream> instead of stdio.h
make a function out of that code then send the strings to it.
if you mean char yes;
then just delete them.
put a system pause between letters. Assuming you are coding on MS-Windows.
#include <windows.h>
...
...
string msg = "This is a test";
for(int i = 0; i < msg.length(); i++)
{
cout << msg[i]; cout.flush();
sleep(1000); // delay 1 second
}
delete line 40 because it is hiding the declaration in the class itself.
Well, you have to change the rest of your code too so that it uses 'y' and 'n' instead of yes and no.
First, get rid of that global cArray. In the class constructor allocate the required number of elements, such as aPtr = new Course[MAX];
. You will also have to create a class destructor to destroy that array with the delete[] operator.
Post code to get any help.
code tags: look in the Quick Reply box and you will see an explanation of them in the watermarks (light grey text). If you can not see them, then just put [code] at the beginning of the code and [/code] at the end, like this:
[code]
// your program goes here
[/code]
First problem is that aPtr is declared in the class constructor. It needs to be declared in the class itself so that it can be accessed by other class methods.
What is cArray? You should probably post the class itself so that we can see what you are doing.
Edit your post and use code tags to make it easier to tell you what is wrong with it.
For starters, you do not need the two variables called yes and no. What you have to do is check for 'y' or 'n' if( yn == 'y')
And remember: = is the assignment operator, == is the comparison operator. Don't confuse the two.
use the mod % operator to check of the number is odd or even. When (number % 2) == 0 the number is even.
make the data type of number an int, not a char because you can't enter a number greater than one digit in a char. You will also have to change the while loop on line 26 while( number != 0)
Interesting assignment, except for the requirement to use system("cls")
to clear the screen. But that's your teacher's problem, not yours.
1) Your validation for months should test if the number entered is less than 1 or greater than 12. If it is, then print an error message and make the user re-enter.
2) You need to use { and } around the while statement beginning on line 43. Without them only line 45 will get executed within that loop.
What dialog box -- there are no buttons or menu item to do that.
Like this:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
if( checkBox1->Checked)
{
MessageBox::Show( "CheckBox1 was chedked.", "Warning",
MessageBoxButtons::OK, MessageBoxIcon::Exclamation );
}
if( checkBox2->Checked)
{
MessageBox::Show( "CheckBox2 was chedked.", "Warning",
MessageBoxButtons::OK, MessageBoxIcon::Exclamation );
}
}
I don't know of any workaround, but then I have not done all that much CLR programming.
put something, such as getchar(), at the end of main() to prevent the window from closing.
The last example can't be compled with the express edition.
First you will need a medical degree so that you know how to recognize a cataract when you see one. My eye specialist had to shine a bright light in my eyes in order to find them. Maybe you can do the same with a color picture -- maybe not. I don't know.
There are lots of different compilers for the same os too -- its called competition.
That code is already sending something on line 41.
>>i just thought i can treat the string array as a 2d char array
You can not do that because it isn't a 2d char array.
This is what I get when I run your program
um..
consider if in the main program, after the statement int k = a.getx();
we add one statements like cout <<k; what will that cout syntax print ? is 2 or 1 ?
The program will not execute because the compiler will not create the program. You will have to fix the error.
your program has a lot of other problems with those if statements. You can't just add digits to the strings like you are doing because there is no memory available for them. Use the += operator and remove [j] notation. Like this: arrconv[i]+='1';
If you are going to use new on line 16 then you have to delete[] it sometime later. Without that your program has a huge memory leak. Avoid that whole issue by not using pointers, declare the array on the stack. 30 strings is not going to cause stack overflow.
'g' and 'h' if statements appears twice.
A switch statement might be easier to code and read instead of all those if statements.
In the case of that function just call it like any other function that does not have the const keyword. The const keyword does nothing more than tell you that the function does not change anything. The following code will produce an error
class A
{
public:
A() {x = 1;}
int getx() const
{
x = 2; // <<< ERROR HERE
return x;
}
private:
int x;
};
int main()
{
A a;
int k = a.getx();
return 0;
}
Well the homework i have been given was to design and make a program that would convert binary code into a denary integer also backwards from denary to binary code.
I have done a bit of research through the internet, and i have seen some simple programs just by using text boxes and buttons to convert. But atm i do not know much about programming as i am a begginer, if anyone has any free time or have anything that could help me do my homework plz
Thanks ;)
Post your question in the appropriate language forum and people will help you with it.
That is not a new feature -- its been there for billions of years :)