d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C++ Problem > Hoping For A Solution
Prev12
Add Reply New Topic New Poll
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Sep 27 2012 11:08pm
Quote (Speed93 @ Sep 27 2012 11:10pm)
How do I get it to print the characters between the two the user inputs?
And its only printing the first line of the characters


your logic is flawed.

when is char1 ever greater than or equal to char2

also you are incrementing char1 every cout statement.

you should be adding char1++; at the top of the loop then just simply print out char1
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Sep 28 2012 04:05am
Quote (Speed93 @ 27 Sep 2012 21:10)
How do I get it to print the characters between the two the user inputs?
And its only printing the first line of the characters


Example input:
A
C

You want it to print the value (base 8-10-16) of 'B' (because it's in between 'A' and 'C')?
What if the user enters "A" and "A?" Now what?
Member
Posts: 9,916
Joined: May 11 2007
Gold: 3,280.00
Sep 28 2012 09:46am
Quote (AbDuCt @ Sep 28 2012 01:08am)
your logic is flawed.

when is char1 ever greater than or equal to char2

also you are incrementing char1 every cout statement.

you should be adding char1++; at the top of the loop then just simply print out char1


Code
#include <iostream>
#include <cmath>
using namespace std;

int main(void)
{
//Variable Declarations

char char1;
char char2;



cout << "Please enter the first of two characters: ";
cin  >> char1;

cout << "Please enter the second of the two characters: ";
cin  >> char2;
cout << endl<<endl;

//Row 1 Headers
cout.width(15);
cout << "Character";

cout.width(15);
cout << "Decimal";

cout.width(15);
cout << "Octal";

cout.width(20);
cout << "Hexadecimal";
cout << endl<<endl;

cout.width(11);
cout << char1;

cout.width(16);
cout << dec << static_cast<int>(char1);

cout.width(17);
cout << oct << static_cast<int>(char1);

cout.width(16);
cout << hex << static_cast<int>(char1);
cout << endl;

while
 (char1<char2)
{
 char1=char1++;
 
 cout.width(11);
 cout << char1;

 cout.width(16);
 cout << dec << static_cast<int>(char1);

 cout.width(17);
 cout << oct << static_cast<int>(char1);

 cout.width(16);
 cout << hex << static_cast<int>(char1);
 cout << endl;
}

while
 (char1>char2)
{
 char1=char1--;
 cout.width(11);
 cout << char1;

 cout.width(16);
 cout << dec << static_cast<int>(char1);

 cout.width(17);
 cout << oct << static_cast<int>(char1);

 cout.width(16);
 cout << hex << static_cast<int>(char1);
 cout << endl;

 if
  (char1==char2)
  break;

}


Thanks guys I finally got it :)

This post was edited by Speed93 on Sep 28 2012 09:55am
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Sep 28 2012 09:56am
I'm not sure if you're asking us to do the assignment for you, or just for directions.

In any case, in general terms, that's what you need to do:

1. Gather user input (char1, char2)
2. Determine order of display (ascending or descending?)
3. Iterate over values you want to display in the order you want
4. For each iteration, pretty-print whatever you were supposed to print

edit: gj

This post was edited by KrzaQ2 on Sep 28 2012 09:57am
Member
Posts: 9,916
Joined: May 11 2007
Gold: 3,280.00
Sep 28 2012 10:05am
Quote (KrzaQ2 @ Sep 28 2012 11:56am)
I'm not sure if you're asking us to do the assignment for you, or just for directions.

In any case, in general terms, that's what you need to do:

1. Gather user input (char1, char2)
2. Determine order of display (ascending or descending?)
3. Iterate over values you want to display in the order you want
4. For each iteration, pretty-print whatever you were supposed to print

edit: gj


And no in no way or form am I asking someone to write this for me, I was asking specific questions and I did get to a solution :), regardless that this is the only c++ course I need to take having someone write the programs for me wouldn't benefit me whatso ever :)
Go Back To Programming & Development Topic List
Prev12
Add Reply New Topic New Poll