Need help with some code....

This is a discussion on Need help with some code.... within the C++ Programming forums, part of the General Programming Boards category; I'm new here and I need to know how to change a sentence in lowercase to uppercase and output the ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    6

    Need help with some code....

    I'm new here and I need to know how to change a sentence in lowercase to uppercase and output the uppercase sentence to a file.
    What other code do I need for this?
    Here is what i have so far:

    Code:
    #include <iostream>
    #include <fstream>
    #include <cctype>
    #include <cstdlib>
    
    using namespace std;
    
    int main()
    {
    
    	using namespace std;
    	ofstream out_stream;
    
    	
    	out_stream.open("lowertoupperoutfile.dat");
    
    	out_stream << ("hello this is the paragraph part of the project.\n");
    
    	out_stream.close();
    	
    
    	return 0;
    
    }

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    here is a c++ solution that only converts the string from lower-case to upper-case. After the conversion your program needs to write it out to a file.
    Code:
    #include <iostream>
    #include <string>
    #include <algorithm>
    using namespace std;
    
    int main()
    {
    	string s = "this is lower case";
    	transform(s.begin(),s.end(),s.begin(),toupper);
    	cout << s << endl;
    	return 0;
    }
    you should learn to search the boards -- here it another solution.
    Last edited by Ancient Dragon; 11-06-2005 at 08:28 PM.

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,062
    OOooo better than mine... and you beat me to the punch.

    Code:
    #include <iostream>
    #include <string>
    #include <cctype>
    
    using namespace std;
    
    int main() {
    
        string str1;
    
        cout << "Enter in a string in lowercase \n";
        getline(cin, str1,'\n');
    
        for (int x = 0; str1[x] !=0; x++)
            str1[x] = toupper(str1[x]);
    
        cout << str1;
    
        return 0;
    
        }
    Sent from my iPad®

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by SlyMaelstrom
    OOooo better than mine... and you beat me to the punch.
    I learned that here on this board too

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    6
    Sweet! I got it know, thanks fellas.

    Here is my final code:
    Code:
    #include <iostream>
    #include <fstream>
    #include <cctype>
    #include <algorithm>
    #include <string>
    
    using namespace std;
    
    int main()
    {
    
    	using namespace std;
    	ofstream out_stream;
    
    	
    	out_stream.open("lowertoupperoutfile.dat");
    
    	string s = ("hello this is the paragraph part of the project.\n");
    	transform(s.begin(),s.end(),s.begin(),toupper);
    	
    	out_stream << s << endl;
    	
    	
    	out_stream.close();
    	
    
    	return 0;
    
    }
    You guys are EPIC.

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Code:
    string s = ("hello this is the paragraph part of the project.\n");
    You can omit the parentheses -- that is an assignment, not a function call. Or do it like this:
    Code:
    string s ("hello this is the paragraph part of the project.\n");

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    6
    Ok, cool.

  8. #8
    Registered User
    Join Date
    Nov 2005
    Posts
    6
    I have one more question/project that I need to ask.
    I hope this isn't to much to ask but here goes, you don't have to look at it if you don't want but here:

    I need to add another loan to it to make it 2 loans and input a function called initialize _loan to initialize the loan struct and also display the loan and monthly payment for each.

    I don't really know where to add or put a second loan part to this, and put the function in there. Any help would be appreciated. I'm kind of lost. Here is the first loan code part:

    Code:
    #include<iostream>
    #include<cmath>
    using namespace std;
    
    struct Loan
    {
    	int ID;
    	float amount;
    	float rate;
    	int term;
    };
    
    float payment(Loan 1);
    
    int main()
    {
    	Loan loan1;
    	float monthly_payment;
    
    	cout << "Enter the ID of this loan \n";
    	cin >> loan1.ID;
    
    	cout << "Enter the amount of this loan \n";
    	cin >> loan1.amount;
    
    	cout << "Enter the annual interest rate of this loan (in%)\n";
    	cin >> loan1.term;
    
    	monthly_payment = payment(loan1);
    
    	cout << "The monthly payment for loan " << loan.ID << "is:" <<monthly_payment << endl;
    
    	return 0;
    
    }
    
    float payment(Loan 1)
    {
    	1.rate/1200;
    	return 1.amount*1.rate*( pow((1.rate+1),1.term)/(pow((1.rate+1),1.term) - 1));
    }
    Thanks in advance.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21