views:

169

answers:

2

If I have an input text with the only thing written of "A" and I want a series of code that will allow me to generate the next ASCII set (B), how would I do so?

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}

#include iostream>
#include fstream>
#include iomanip>
#include string>

using namespace std;

int main()
{

ifstream inFile;

ofstream outFile;

    string firstName;
    string lastName;
    string character;

    int age;
    double rectangle, length, width, area, parameter, circle, radius, areaCircle, circumference, beginningBalance, interestRate, endBalance;

    inFile.open("inData.txt");
    outFile.open("outData.txt");

    outFile << fixed << showpoint;
    outFile << setprecision(2);

    cout << "Data is processing..." << endl;

    inFile >> length >> width;
    area = length * width;
    parameter = (length * 2) + (width *2);
    outFile << "Rectangle:" << endl;
    outFile << "Length = " << length << " " << "width = " << width << " " << "area = " << area << " " << "parameter = " << parameter << endl;

    inFile >> radius;
    outFile << " " << endl;
    outFile << "Cricle:" <<endl;
    areaCircle = 3.14159 * (radius * radius);
    circumference = 2 * (3.14159 * radius);
    outFile << "Radius = " << radius << " " << "area = " << areaCircle << " " << "circumference = " << circumference;

    outFile << endl;
    outFile << endl;

    inFile >> firstName >> lastName >> age;
    outFile << "Name: " << firstName << " " << lastName << "," << " " << "age: " << age;

    outFile << endl;

    inFile >> beginningBalance >> interestRate;
    outFile << "Beginning balance = " << beginningBalance << "," << " " << "interest rate = " << interestRate << endl;
    endBalance = ((18500 * .0350) / 12.0 ) + 18500;
    outFile << "Balance at the end of the month = $" << endBalance;

    outFile << endl;
    inFile >> character;
    outFile << "The character that comes after" << character << "in the ASCII set is" << character +1;



        inFile.close();
    outFile.close();

    return 0;

}
+1  A: 
char c = 'A';
char next_one = c+1;

This gives you the next character ('B' here), assuming ASCII. As this seems to be homework, you need to do the rest of the work by yourself.

Alexander Gessler
can you help me again.
Sagistic
@user 278330: What do you need help with?
Javier Badia
I'm trying to make it so that at the end, the code reads the text file (which contains the letter A), and then will display the next character (so if i put C instead of A in the text file, it will display D)
Sagistic
+1  A: 

Instead of declaring character as a string, declare it as a char. string refers to std::string, a high-level object for storing multiple characters. char is a low-level native type which stores exactly 1 character.

char character;
infile >> character;
outfile << "next after " << character << " is " << char(character+1) << endl;

input of Z or besides letters notwithstanding.

Potatoswatter
Thank you, but now my outdata reads as " The character that comes after A in the ASCII set is 66"
Sagistic
Sorry, fixed. The problem is that `1` is of type `int`, and `int` is a "bigger" type than `char`, and when you add numbers of different types the result is of the larger type, and hence it printed `B` as an `int`. `outfile << ++ character;` would also print the right thing, but would modify `character`.
Potatoswatter
THANK YOU!!!!!!! WOOHOOOO!! I was stumped for soo long and my textbook didn't really go over it. Sincerest Gratitude.
Sagistic