Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

formatting

scuba22scuba22 Member Posts: 61
hi all, what's wrong with my formatting?
my outfile consistently has "Blaise's" running score slightly out of line...especially the final 2 or 3 numbers...
kinda driving me nuts :-D
[code]#include
#include
#include
#include
#include
using namespace std;


//function prototype
int pp (int&);
int main()
{

ofstream outfile("A:\0F1017_6_2.txt");

if(!outfile){
cerr << "Cannot open output file" << endl;
}
srand((unsigned) time(0));
int a = 0;
int b = 0;
int aa = 0;
int bb = 0;
int i = 0;
int score = 0;


for (int pg=0; pg < 3;pg++)
{

outfile << "
Game " << pg+1 << endl;

bool zz = true;
if (zz == true)
{
outfile << setw(11) << "
Ada" << setw(16) << "Blaise" << endl;
bool zz = false;
}


for (;;)
{

score = pp(score);
if (i!= 0)
{
if (score == 1)
{
outfile << setw (20) << a+1 <<setw(15)<< b << endl;
a++;
aa++;
}
else
{
outfile << setw (20)<< a << setw(15) << b+1 << endl;
b++;
bb++;
}


if (a == 11)
{
outfile << setw(10) << " Ada won 11 to " << b << endl;
a = 0;
b = 0;
break;
}
else if (b == 11)
{
outfile << setw(10) << " Blaise won 11 to " << a << endl;
a = 0;
b = 0;
break;
}

}

i++;
}
}
outfile <<"
";
if ( aa > bb ){
outfile << "Ada is the overall winner
";}
else {outfile << "Blaise is the overall winner
";}

return 0;
}

//function pp
int pp (int &score){
score = (1 + rand() % 99);
if (score <= 55)
return 1;
else
return 0;
}
[/code]

Comments

  • brycebryce Member Posts: 25
    I ran this and received 7 errors to begin with. First
    do you not need to open outfile .

    Next there is 1 possible error that may just show a warning
    at times with some compilers.

    I did cast this to force the compiler with this area.
    outfile << "
    Game " << /*note*/(pg)+1 << endl;

    I think you need to address these portions before any
    formatting.

    Are you speaking of Pascal? Quite the collector eh :-)

    Bryce

    : hi all, what's wrong with my formatting?
    : my outfile consistently has "Blaise's" running score slightly out of line...especially the final 2 or 3 numbers...
    : kinda driving me nuts :-D
    : [code]#include<iostream>
    : #include
    : #include
    : #include
    : #include
    : using namespace std;
    :
    :
    : //function prototype
    : int pp (int&);
    : int main()
    : {
    :
    : ofstream outfile("A:\0F1017_6_2.txt");
    :
    : if(!outfile){
    : cerr << "Cannot open output file" << endl;
    : }
    : srand((unsigned) time(0));
    : int a = 0;
    : int b = 0;
    : int aa = 0;
    : int bb = 0;
    : int i = 0;
    : int score = 0;
    :
    :
    : for (int pg=0; pg < 3;pg++)
    : {
    :
    : outfile << "
    Game " << pg+1 << endl;
    :
    : bool zz = true;
    : if (zz == true)
    : {
    : outfile << setw(11) << "
    Ada" << setw(16) << "Blaise" << endl;
    : bool zz = false;
    : }
    :
    :
    : for (;;)
    : {
    :
    : score = pp(score);
    : if (i!= 0)
    : {
    : if (score == 1)
    : {
    : outfile << setw (20) << a+1 <<setw(15)<< b << endl;
    : a++;
    : aa++;
    : }
    : else
    : {
    : outfile << setw (20)<< a << setw(15) << b+1 << endl;
    : b++;
    : bb++;
    : }
    :
    :
    : if (a == 11)
    : {
    : outfile << setw(10) << " Ada won 11 to " << b << endl;
    : a = 0;
    : b = 0;
    : break;
    : }
    : else if (b == 11)
    : {
    : outfile << setw(10) << " Blaise won 11 to " << a << endl;
    : a = 0;
    : b = 0;
    : break;
    : }
    :
    : }
    :
    : i++;
    : }
    : }
    : outfile <<"
    ";
    : if ( aa > bb ){
    : outfile << "Ada is the overall winner
    ";}
    : else {outfile << "Blaise is the overall winner
    ";}
    :
    : return 0;
    : }
    :
    : //function pp
    : int pp (int &score){
    : score = (1 + rand() % 99);
    : if (score <= 55)
    : return 1;
    : else
    : return 0;
    : }
    : [/code]
    :

  • scuba22scuba22 Member Posts: 61
    :
    7 errors?
    it runs perfectly on my visual c++...
    Hmmm
    where?
    why not open an outfile?
    ya gotta give me more info..
    M







    I ran this and received 7 errors to begin with. First
    : do you not need to open outfile .
    :
    : Next there is 1 possible error that may just show a warning
    : at times with some compilers.
    :
    : I did cast this to force the compiler with this area.
    : outfile << "
    Game " << /*note*/(pg)+1 << endl;
    :
    : I think you need to address these portions before any
    : formatting.
    :
    : Are you speaking of Pascal? Quite the collector eh :-)
    :
    : Bryce
    :
    : : hi all, what's wrong with my formatting?
    : : my outfile consistently has "Blaise's" running score slightly out of line...especially the final 2 or 3 numbers...
    : : kinda driving me nuts :-D
    : : [code]#include<iostream>
    : : #include
    : : #include
    : : #include
    : : #include
    : : using namespace std;
    : :
    : :
    : : //function prototype
    : : int pp (int&);
    : : int main()
    : : {
    : :
    : : ofstream outfile("A:\0F1017_6_2.txt");
    : :
    : : if(!outfile){
    : : cerr << "Cannot open output file" << endl;
    : : }
    : : srand((unsigned) time(0));
    : : int a = 0;
    : : int b = 0;
    : : int aa = 0;
    : : int bb = 0;
    : : int i = 0;
    : : int score = 0;
    : :
    : :
    : : for (int pg=0; pg < 3;pg++)
    : : {
    : :
    : : outfile << "
    Game " << pg+1 << endl;
    : :
    : : bool zz = true;
    : : if (zz == true)
    : : {
    : : outfile << setw(11) << "
    Ada" << setw(16) << "Blaise" << endl;
    : : bool zz = false;
    : : }
    : :
    : :
    : : for (;;)
    : : {
    : :
    : : score = pp(score);
    : : if (i!= 0)
    : : {
    : : if (score == 1)
    : : {
    : : outfile << setw (20) << a+1 <<setw(15)<< b << endl;
    : : a++;
    : : aa++;
    : : }
    : : else
    : : {
    : : outfile << setw (20)<< a << setw(15) << b+1 << endl;
    : : b++;
    : : bb++;
    : : }
    : :
    : :
    : : if (a == 11)
    : : {
    : : outfile << setw(10) << " Ada won 11 to " << b << endl;
    : : a = 0;
    : : b = 0;
    : : break;
    : : }
    : : else if (b == 11)
    : : {
    : : outfile << setw(10) << " Blaise won 11 to " << a << endl;
    : : a = 0;
    : : b = 0;
    : : break;
    : : }
    : :
    : : }
    : :
    : : i++;
    : : }
    : : }
    : : outfile <<"
    ";
    : : if ( aa > bb ){
    : : outfile << "Ada is the overall winner
    ";}
    : : else {outfile << "Blaise is the overall winner
    ";}
    : :
    : : return 0;
    : : }
    : :
    : : //function pp
    : : int pp (int &score){
    : : score = (1 + rand() % 99);
    : : if (score <= 55)
    : : return 1;
    : : else
    : : return 0;
    : : }
    : : [/code]
    : :
    :
    :

  • brycebryce Member Posts: 25
    looks like ada wins.
    Thank god...

    Game 1

    Ada Blaise
    1 0
    1 1
    1 2
    2 2
    3 2
    4 2
    4 3
    4 4
    4 5
    5 5
    6 5
    7 5
    7 6
    7 7
    7 8
    8 8
    9 8
    10 8
    11 8
    Ada won 11 to 8

    Game 2

    Ada Blaise
    1 0
    1 1
    1 2
    1 3
    2 3
    3 3
    4 3
    4 4
    4 5
    4 6
    5 6
    6 6
    6 7
    7 7
    7 8
    8 8
    8 9
    9 9
    10 9
    10 10
    10 11
    Blaise won 11 to 10

    Game 3

    Ada Blaise
    1 0
    1 1
    2 1
    2 2
    3 2
    3 3
    3 4
    3 5
    3 6
    4 6
    4 7
    4 8
    4 9
    5 9
    6 9
    7 9
    8 9
    8 10
    9 10
    10 10
    11 10
    Ada won 11 to 10

    Ada is the overall winner
    Bryce

    : hi all, what's wrong with my formatting?
    : my outfile consistently has "Blaise's" running score slightly out of line...especially the final 2 or 3 numbers...
    : kinda driving me nuts :-D
    : [code]#include
    : #include
    : #include
    : #include
    : #include
    : using namespace std;
    :
    :
    : //function prototype
    : int pp (int&);
    : int main()
    : {
    :
    : ofstream outfile("A:\0F1017_6_2.txt");
    :
    : if(!outfile){
    : cerr << "Cannot open output file" << endl;
    : }
    : srand((unsigned) time(0));
    : int a = 0;
    : int b = 0;
    : int aa = 0;
    : int bb = 0;
    : int i = 0;
    : int score = 0;
    :
    :
    : for (int pg=0; pg < 3;pg++)
    : {
    :
    : outfile << "
    Game " << pg+1 << endl;
    :
    : bool zz = true;
    : if (zz == true)
    : {
    : outfile << setw(11) << "
    Ada" << setw(16) << "Blaise" << endl;
    : bool zz = false;
    : }
    :
    :
    : for (;;)
    : {
    :
    : score = pp(score);
    : if (i!= 0)
    : {
    : if (score == 1)
    : {
    : outfile << setw (20) << a+1 <<setw(15)<< b << endl;
    : a++;
    : aa++;
    : }
    : else
    : {
    : outfile << setw (20)<< a << setw(15) << b+1 << endl;
    : b++;
    : bb++;
    : }
    :
    :
    : if (a == 11)
    : {
    : outfile << setw(10) << " Ada won 11 to " << b << endl;
    : a = 0;
    : b = 0;
    : break;
    : }
    : else if (b == 11)
    : {
    : outfile << setw(10) << " Blaise won 11 to " << a << endl;
    : a = 0;
    : b = 0;
    : break;
    : }
    :
    : }
    :
    : i++;
    : }
    : }
    : outfile <<"
    ";
    : if ( aa > bb ){
    : outfile << "Ada is the overall winner
    ";}
    : else {outfile << "Blaise is the overall winner
    ";}
    :
    : return 0;
    : }
    :
    : //function pp
    : int pp (int &score){
    : score = (1 + rand() % 99);
    : if (score <= 55)
    : return 1;
    : else
    : return 0;
    : }
    : [/code]
    :

  • scuba22scuba22 Member Posts: 61
    : well Ada DOES have a slight (56%) edge....
    I have tried to give blaise more room with setw but 'snot working...
    that's why I'm askin You!! :-D




    looks like ada wins.
    : Thank god...
    :
    : Game 1
    :
    : Ada Blaise
    : 1 0
    : 1 1
    : 1 2
    : 2 2
    : 3 2
    : 4 2
    : 4 3
    : 4 4
    : 4 5
    : 5 5
    : 6 5
    : 7 5
    : 7 6
    : 7 7
    : 7 8
    : 8 8
    : 9 8
    : 10 8
    : 11 8
    : Ada won 11 to 8
    :
    : Game 2
    :
    : Ada Blaise
    : 1 0
    : 1 1
    : 1 2
    : 1 3
    : 2 3
    : 3 3
    : 4 3
    : 4 4
    : 4 5
    : 4 6
    : 5 6
    : 6 6
    : 6 7
    : 7 7
    : 7 8
    : 8 8
    : 8 9
    : 9 9
    : 10 9
    : 10 10
    : 10 11
    : Blaise won 11 to 10
    :
    : Game 3
    :
    : Ada Blaise
    : 1 0
    : 1 1
    : 2 1
    : 2 2
    : 3 2
    : 3 3
    : 3 4
    : 3 5
    : 3 6
    : 4 6
    : 4 7
    : 4 8
    : 4 9
    : 5 9
    : 6 9
    : 7 9
    : 8 9
    : 8 10
    : 9 10
    : 10 10
    : 11 10
    : Ada won 11 to 10
    :
    : Ada is the overall winner
    : Bryce
    :
    : : hi all, what's wrong with my formatting?
    : : my outfile consistently has "Blaise's" running score slightly out of line...especially the final 2 or 3 numbers...
    : : kinda driving me nuts :-D
    : : [code]#include
    : : #include
    : : #include
    : : #include
    : : #include
    : : using namespace std;
    : :
    : :
    : : //function prototype
    : : int pp (int&);
    : : int main()
    : : {
    : :
    : : ofstream outfile("A:\0F1017_6_2.txt");
    : :
    : : if(!outfile){
    : : cerr << "Cannot open output file" << endl;
    : : }
    : : srand((unsigned) time(0));
    : : int a = 0;
    : : int b = 0;
    : : int aa = 0;
    : : int bb = 0;
    : : int i = 0;
    : : int score = 0;
    : :
    : :
    : : for (int pg=0; pg < 3;pg++)
    : : {
    : :
    : : outfile << "
    Game " << pg+1 << endl;
    : :
    : : bool zz = true;
    : : if (zz == true)
    : : {
    : : outfile << setw(11) << "
    Ada" << setw(16) << "Blaise" << endl;
    : : bool zz = false;
    : : }
    : :
    : :
    : : for (;;)
    : : {
    : :
    : : score = pp(score);
    : : if (i!= 0)
    : : {
    : : if (score == 1)
    : : {
    : : outfile << setw (20) << a+1 <<setw(15)<< b << endl;
    : : a++;
    : : aa++;
    : : }
    : : else
    : : {
    : : outfile << setw (20)<< a << setw(15) << b+1 << endl;
    : : b++;
    : : bb++;
    : : }
    : :
    : :
    : : if (a == 11)
    : : {
    : : outfile << setw(10) << " Ada won 11 to " << b << endl;
    : : a = 0;
    : : b = 0;
    : : break;
    : : }
    : : else if (b == 11)
    : : {
    : : outfile << setw(10) << " Blaise won 11 to " << a << endl;
    : : a = 0;
    : : b = 0;
    : : break;
    : : }
    : :
    : : }
    : :
    : : i++;
    : : }
    : : }
    : : outfile <<"
    ";
    : : if ( aa > bb ){
    : : outfile << "Ada is the overall winner
    ";}
    : : else {outfile << "Blaise is the overall winner
    ";}
    : :
    : : return 0;
    : : }
    : :
    : : //function pp
    : : int pp (int &score){
    : : score = (1 + rand() % 99);
    : : if (score <= 55)
    : : return 1;
    : : else
    : : return 0;
    : : }
    : : [/code]
    : :
    :
    :

  • Shawn CarterShawn Carter Member Posts: 0

    _______ // http://forcoder.org // free ebooks and video tutorials about [ MATLAB Ruby C Go JavaScript C++ PHP Scratch R Assembly Swift Java Objective-C Perl Python C# PL/SQL Visual Basic Delphi Visual Basic .NET Dart Lua Crystal FoxPro Rust Ada Clojure Transact-SQL COBOL LabVIEW F# Awk SAS Bash Logo Julia Lisp Scheme D ABAP Scala Fortran VBScript Alice Hack Erlang ML Kotlin Apex Prolog ] _______

Sign In or Register to comment.