Hey all,
I am having a little bit of trouble wrapping this segment up.
I need a for loop that will wrap a 3 digit number (i.e. 320) vertically so that it displays like below.
3
2
0
instead of...
320
Here is the code I have already:
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<cctype>
#include<string>
using namespace std;
int main()
{
//-----------------------------------------------------------------------------------------------------------------------------------------------
//Filestream Object Declaration
ofstream alphabet( "C:\\alphabet.txt" ) ;
//-----------------------------------------------------------------------------------------------------------------------------------------------
//Variable Declarations
string sentence ;
//-----------------------------------------------------------------------------------------------------------------------------------------------
//User Input Prompt
cout << "Please type a compilation of alphabet characters in no particular format below, press 'Enter' to count alphabet characters.\n" << endl;
//-----------------------------------------------------------------------------------------------------------------------------------------------
//Capture User Input Store In string 'sentence'
getline( cin, sentence );
//-----------------------------------------------------------------------------------------------------------------------------------------------
//Error occurrence of file write to user
if( ! alphabet )
{
cout << "Error occurred while attempting to open 'C:\\alphabet.txt'." << endl ;
return -1 ; // Error signal occurrence
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
//Successful occurrence of file write to user
else
{
cout << endl;
cout << "Character compilation saved successfully to 'C:\\alphabet.txt'!" << endl ;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
// Write User Input To File 'C:\\alphabet.txt'
alphabet << sentence << endl;
//-----------------------------------------------------------------------------------------------------------------------------------------------
// Close Filestream
alphabet.close();
//-----------------------------------------------------------------------------------------------------------------------------------------------
//***********************************************************************************************************************************************
//***********************************************************************************************************************************************
//***********************************************************************************************************************************************
//Variable Declarations
int count[26] = {0} ;
char c ;
int nonletter = 0 ;
//-----------------------------------------------------------------------------------------------------------------------------------------------
//Input Filestream Object
ifstream readAlphabet( "C:\\alphabet.txt" ) ;
//-----------------------------------------------------------------------------------------------------------------------------------------------
//Error occurrence of file input to user
if( ! readAlphabet )
{
cout << "Error occurred while attempting to open 'C:\\alphabet.txt'." << endl ;
return -1 ; // Error signal occurrence
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
//Successful occurrence of file input to user
else
{
cout << endl;
cout << "'C:\\alphabet.txt' successfully input to program!" << endl ;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
//***********************************************************************************************************************************************
//***********************************************************************************************************************************************
//***********************************************************************************************************************************************
//PROCESS THE FILE
readAlphabet.get(c);
//-----------------------------------------------------------------------------------------------------------------------------------------------
//WHILE LOOP
while ( ! readAlphabet.eof() )
{
c = tolower(c) ; // Make all characters lower case
//-----------------------------------------------------------------------------------------------------------------------------------------------
if (c >= 'a' && c <= 'z')
{
count[c - 'a']++ ;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
else
{
nonletter++ ;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
readAlphabet.get(c) ;
//-----------------------------------------------------------------------------------------------------------------------------------------------
}//***END WHILE LOOP***
//-----------------------------------------------------------------------------------------------------------------------------------------------
//Display Number Of Characters
cout << endl ;
cout << "Character counts: " << endl;
//-----------------------------------------------------------------------------------------------------------------------------------------------
for( c = 0 ; c < 26 ; c++ )
{
cout << ( char )( 'a'+ c ) << " " ;
}//***END ***
//-----------------------------------------------------------------------------------------------------------------------------------------------
cout << "\n" ;
//-----------------------------------------------------------------------------------------------------------------------------------------------
for( c = 0 ; c < 26 ; c++ )
{
cout << count[c] << endl << " " ;
}//***END ***
//-----------------------------------------------------------------------------------------------------------------------------------------------
cout << endl << count[1] ;
//-----------------------------------------------------------------------------------------------------------------------------------------------
return 0;
}//***END main FUNCTION***