My problem is to complete a partially written C++ program that includes two functions that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a function that computes the sum of all the whole numbers from 1 up to and including the entered number. next the program passes the value to another function that computes the product of all the whole numbers up to and including the entered number. here is my code. I am trying to just call the function sums and no matter what I put in () I get an error when compiling I am trying to work in steps but can't get pass the first part. Following my book it seems like I am trying the right things but to no avail.
// SumAndProduct.cpp - This program computes sums and products
// Input: Interactive
// Output: Computed sum and product
#include <iostream>
#include <string>
int number1, number2;
void sums(int);//function declaration
void products(int);//function declaration
using namespace std;
int main()
{
double number; //this is a global variable
cout << "Enter a positive integer or 0 to quit: ";
cin >> number;
while(number != 0)
{
// Call sums function here
sums(number);// I have tried to enter sums(int number1, int number 2) or (double number). I am receiving an error expected primary expression before int.
I am not sure what I am doing wrong, I have looked at examples in the book and they all seem to be following what I have tried to put in.
void sums(int);//function declaration
...
double number; //this is a global variable
...
sums(number);
You've declared that sums() accepts a single integer, but when you call it you're trying to pass a double.
BTW, number is not a global variable. It is a local variable with main().
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.