Hi.
I am currently learning c++, by reading and doing exersises if find online.
The exersis askes me to create a program that find the mean of 1,2,3 or 4 numbers.
I know this can be done easily by writing one "small program" for each of the situations, but I want to try to make it a bit more advance.
I want to use a char array where the numbers are seperated like this 1,2,3,7 and so one.
But I have a few questions, how can I make sure the input given is a number? I was thinking of converting it to ancii, but it has to be a better way?
And if I use a loop to assign the value from the char array to an int array, how can I do so that every whole number is placed at the same space? So that no[1] = 12, insted of no[1] = 1 and no[2] = 2
here is my code so far:
EDIT:Code:#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
char numbers[100];
int no[100];
//This will give the info about the program and how to use it
cout <<"This program will to two things:\n";
cout <<" - Find the average\n";
cout <<" - Find the standar diviation\n\n";
cout <<"How to use:\n";
cout <<"Enter the values you would like to use for this exsample,\n";
cout <<"please seperate them with a blank space " ":\n";
//store the info in a variable for later use
cin.getline ( numbers, 100, '\n' );
//loop through the string and exstract the number
//store it in a new variable
for (int i = 0; i < 100; i++)
{
if (numbers[i] == ",")
{
//It is a seperator, nothing happesns
//The loop just continius
}
else
{
no[i] = numbers[i];
}
}
cout <<"\n\n\n";
system("PAUSE");
return 0;
}
Why is the line "if (numbers[i] == ",")" not valid?
thanks in advance