Thread: Table Homework

  1. #1
    Your Father
    Join Date
    Sep 2005
    Posts
    34

    Table Homework

    I have to make this table for my class:
    Enter num1:
    Enter num2(must be greater than 16):
    output:
    num1 num2 num3 sum1 sum2 prod1 prod2 quot1 quot2 rmd
    2 20 20 22 22 40 40 0 0.1 2
    6 16 16 22 22 96 96 0 0.375 6
    ^ (this num gets multiplied by 3 everytime) and going on for 3 more lines


    Is this going to be very long to write? Do I have to define a variable for each line? I am EXTREMELY new to this, please help .

    BTW i am not asking for answers

    This is what i have so far:
    Code:
     
     #include <iostream>
     #include <string>
     using namespace std;
     int main()
     {
     //DEFINITIONS
     cout << "Please enter the first number: ";
     int num1;
     cin >> num1;
     
     cout << "Please enter the second number (greater than 16): ";
     int num2;
     cin >> num2; 
     float num3;
     num3 = (float)num2;
     float sum1;
     sum1 = num1 + num2;
     float  sum2;
     sum2 = num1 + num3;
     float prod1;
     prod1 = num1 * num2;
     float prod2;
     prod2 = num1 * num3;
     float  quot1;
     quot1 = num1 / num2;
     float quot2;
     quot2 = num1 / num3;
     float  rmd;
     rmd = num1 % num2;
     
     // TABLE
    
    cout << "Num1 Num2 Num3 Sum1 Sum2 Prod1 Prod2 Quot1 Quot2
    Rmd ";
    
     return 0;  
     }
    Last edited by howeezy; 09-23-2005 at 03:40 PM. Reason: clarification

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    C++ ? Moving to the relavant forum.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    I am not sure what the question is?

    You seem to have all the code there, it might not be the neatest or most efficient, but it does what I think you said it has to do.

    Other then output the numbers properly, what is left?

  4. #4
    Your Father
    Join Date
    Sep 2005
    Posts
    34
    sorry this class is so fast I'm just really confused.

    If i made this table wouldnt it need more than one input for num1? The instructions are so vague.

    Or would I have to create a second num1?
    Last edited by howeezy; 09-23-2005 at 04:41 PM.

  5. #5
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    So you want to repeat everything over, and each time it repeats multiply the original number by 3? You want loops.

    http://www.cprogramming.com/tutorial/lesson3.html

    Here is an example of a do-while loop in this context. Read up on that link above to learn more.

    Code:
    #include <iostream>
    using namespace std;
    
    
    int main()
    {
    
    	int number;
    
    	int counter = 0; //This gets incremented by one, counts how many times it has been repeated.
    
    	int calculation1, calculation2;
    
    	cout << "Enter a number: ";
    	cin >> number;
    
    
    
    	do
    	{
    
    
    	calculation1 = (number + number);
    	calculation2 = (calculation1 * number);
    
    	cout << "The numbers are: " << number << " " << calculation1 << " " << calculation2 << endl;
    
    	number = (number * 3);
    	counter++;
    
    
    	}while ( counter <= 5); //5 is a arbitrary number, it can be any hardcoded number or a variables.
    
     
     return 0;
    
    
    }

    After reading up on loops, if you have any questions about this code just ask.

    *edit*

    P.S. It would be best to not include libraries you do not use. Such as <strings> in the code you posted.
    Last edited by Enahs; 09-23-2005 at 04:52 PM.

  6. #6
    Your Father
    Join Date
    Sep 2005
    Posts
    34
    thank you so much i will check it out

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 05:06 PM
  2. progarm doesnt compile
    By kashifk in forum Linux Programming
    Replies: 2
    Last Post: 10-25-2003, 05:54 PM
  3. extra word printing
    By kashifk in forum C++ Programming
    Replies: 2
    Last Post: 10-25-2003, 04:03 PM
  4. inputting words from a file
    By kashifk in forum C++ Programming
    Replies: 5
    Last Post: 10-24-2003, 07:18 AM
  5. help with operator <
    By kashifk in forum C++ Programming
    Replies: 1
    Last Post: 10-21-2003, 03:49 PM