954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C++ Emergency

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; 
}
eyedea2011
Newbie Poster
12 posts since Jul 2007
Reputation Points: 6
Solved Threads: 0
 

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

Infarction
Posting Virtuoso
1,580 posts since May 2006
Reputation Points: 683
Solved Threads: 53
 

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. :)

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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?

eyedea2011
Newbie Poster
12 posts since Jul 2007
Reputation Points: 6
Solved Threads: 0
 

>>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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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?

eyedea2011
Newbie Poster
12 posts since Jul 2007
Reputation Points: 6
Solved Threads: 0
 

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; 
}
eyedea2011
Newbie Poster
12 posts since Jul 2007
Reputation Points: 6
Solved Threads: 0
 

>>if ( islower(str[i])) >= 'a' && str[i] <= '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 
}
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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; 
}
eyedea2011
Newbie Poster
12 posts since Jul 2007
Reputation Points: 6
Solved Threads: 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.

John A
Vampirical Lurker
Team Colleague
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
 

> 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"

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You