Results 1 to 15 of 88

Thread: C++ Help

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Old-Ones Studios Cruise Control's Avatar
    Join Date
    Apr 2005
    Location
    Seattle, WA
    Posts
    3,799

    Default

    This is now the official thread for intermediate C++ students to help each other.

    Dreaper, do you know why this doesn't work, the != doesn't make a difference.
    Code:
    //Chris Taylor
    //February 22, 2006
    //Terminal 6, Intermediate Computer Prgramming.
    //Switch Program
    
    
    //These are my header files.
    #include <conio.h>
    #include <fstream.h>
    #include <iomanip.h>
    #include <iostream.h>
    
    //This is the start of my program.
    int main()
    {
     //prints to the text file.
     ofstream outfile ("500.txt");
    
     //Declaring my variables.
     int cd=5; //number that starts the countdown.
     int r1;   //number that is stored from division of 5.
     int r2;   //number that is stored from modulus of r1.
     int r3;   //number that is stored from division of 7.
     int r4;   //number that is stored from modulus of r3.
     while (cd<500)
     {
      r1=cd/5;
      r2=r1%5;
      r3=cd/7;
      r4=r3%7;
    
      if (r2==0||r4==0)
       cout << cd << ", ";
       cd++;
     }
    
     //That stuff at the end.
     getch();
     return 0;
    }
    EDIT: It works now.
    Code:
    int main()
    {
     ofstream outfile ("PN.txt");
    
     int cd=5; //number that starts the countdown.
     int r1;   //number that is stored from modulus of r1.
     int r2;   //number that is stored from modulus of r3.
    
     while (cd<500)
     {
      r1=cd%5;
      r2=cd%7;
    
      if (r1==0||r2==0)
       cout << cd << ", ";
       cd++;
     }
    
     getch();
     return 0;
    }
    Last edited by Cruise Control; 02-23-2006 at 04:21 PM.
    Leave some shards under the belly
    Lay some grease inside my hand
    It's a sentimental jury
    And the makings of a good plan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •