I'm a student that needs extra emergency help please!! Please help my assignment is already late. I'm trying to get these 2 codes to work but i can't. I have no more ideas, can someone please please help me. I'm using Microsoft Visual C++ to for my codes. Here they are

1--This one should change numbers to text like 32 = thirty two

#include "stdafx.h" 

using namespace System; 

int main (array<System::String ^> ^args) 
{ 
Random ^ generator = gcnew Random; 
int number = generator->Next (0,Int 32::MaxValue-10000) + 100000; 
Console:: WriteLine (L "The value is {0}", number); 

array<string^>^ digitWord = {L" zero", L" one", L" two", L" three", L" four", 
L" five", L" six", L" seven", L" eight", L" nine"}; 

String^ inWords = L""; 

while(number > 0) 
{ 
inWords = digitWord[number % 10]+inWords; 
number /= 10; 
} 
Console::WriteLine(inWords); 
return 0; 
}

.......................................................................................................
2--This should capitalize every other letter

#include <iostream> 
#include <string> 
using std::cout; 
using std::endl; 

int main() 
{ 
char str[] = "What was yor name?"; 
cout << str << endl; // Output the string 

for (unsigned int i = 0; i < strlen(str); i += 2) 
{ 
if (str[i] >= 'a' && str[i] <= 'z') // If lowercase letter 
str[i] -= 32; // change to uppercase 
} 

cout << str << endl; // Output the modified string 
return 0; 
}

Recommended Answers

All 10 Replies

Be more specific as to what's wrong with them. And please use code tags when posting code.

In the second program you should really use islower() macro to check if the character is lower-case. Then use toupper() to convert from lower-case to upper-case, like this:

if( islower(str[i]))
   str[i] = toupper(str[i]);

Otherwise, that program works ok for me. :)

I made the chaqnges you suggested but i got a new error message.
It says to add #include "stdafx.h" when i do that i get this error.
fatal error C1014: too many include files : depth = 1024

I'm stumped again, is it my compiler?

>>I'm stumped again, is it my compiler?
Not your compiler -- its your code. Post your code because I can't see your computer's screen from where I am sitting.

I keep getting an error message that says too many included files c1014-- then it will say add #include "stdafx.h" when i do that i get the same error mesage. Is it my compiler, i'm using MS Visual C++, should i use a different compiler?

Here it is.

#include "stdafx.h"
#include <iostream> 
#include <string> 
using std::cout; 
using std::endl; 

int main() 
{ 
char str[] = "What was yor name?"; 
cout << str << endl; // Output the string 

for (unsigned int i = 0; i < strlen(str); i += 2) 
{ 
if ( islower(str[i])) >= 'a' && str[i] <= 'z') // If lowercase letter 
str[i] = toupper(str[i]); // change to uppercase 
} 

cout << str << endl; // Output the modified string 
return 0; 
}

>>if ( islower(str)) >= 'a' && str <= 'z') // If lowercase letter

wrong syntax. Should be this:


#include <ctype.h> // add this line somewhere after stdafx.h

for (unsigned int i = 0; i < strlen(str); i += 2) 
{ 
       if ( islower(str[i])) // If lowercase letter 
               str[i] = toupper(str[i]); // change to uppercase 
}

I feel like an idiot, i made the changes and go the same error message again, here is the error and the changes in the code.
Error-fatal error C1014: too many include files : depth = 1024

Code:

#include "stdafx.h"
#include <ctype.h>
#include <iostream> 
#include <string> 
using std::cout; 
using std::endl; 

int main() 
{ 
char str[] = "What was yor name?"; 
cout << str << endl; // Output the string 

for (unsigned int i = 0; i < strlen(str); i += 2) 
{ 
if ( islower(str[i])) // If lowercase letter 
str[i] = toupper(str[i]); // change to uppercase 
} 

cout << str << endl; // Output the modified string 
return 0; 
}

@Ancient Dragon: Shouldn't it be cctype since we're in C++?

As for the code itself, it works fine for me. One thing you may want to try is removing the #include "stdafx.h" line. Or post the contents of stdafx.h if you really want a precompiled header.

> It says to add #include "stdafx.h" when i do that i get this error.
Lemme guess, you added this to stdafx.h as well.

"Hello, recursive file inclusion, WTF happened to all my disk space"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.