The program should be print the numbers 0 through 10, along with their values doubled and tripled. The data file contains the necessary variable declarations and output statements.
Example the output:
Single Double Triple
1 2 3
2 4 6
3 6 9
4 8 12
#include <iostream>
#include <cstdlib>
#include <iomanip> // for the function setw(x); which sets x spaces
usingnamespace std;
int main (){
int x = 0, double1, triple; //Rename double to anything else
// int x = 0 ; Forgot semicolon here and you can not declare the same variable twice. What you can do is x = 0 with out int, or do what I did the line above
while (x<=10){
//Here you want to cout x the variable and not "x" the character.
//You can not initialize and cout at the same time, so initialize the variables //then cout them.
double1 = (x*2);
triple = (x*3);
cout << x << setw(5) << double1 <<setw(5) << triple << endl;
x++;
}
return 0; // Missing semicolon here and just return 0 instead of EXIT_SUCCESS, its more common
} // you missed ending bracket
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main ()
{
int x, double, triple; // double is a keyword
int x = 0 // ; needed
while (x<=10)
{
/*
* You need to put "" in here, look at my code.
* Unless you're trying to assign double and triple
* and print them at the same time?
*/
cout << "x" << double = (x*2) << triple = (x*3) << endl;
x++;
}
return EXIT_SUCCESS // ; needed
}
Your code has quite a few errors... I'll fix it for you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main ()
{
int x = 0; //double is a keyword, and isn't needed
while (x<=10)
{
/*
* You need to separate text and variables,
* also, you don't need "double" or "triple", so I've removed them
*/
cout << "single = " << x << " double= " << (x*2) << " triple= " << (x*3) << endl;
x++;
}
return EXIT_SUCCESS;
}