I'm having an issue with my code when doing the For Loop. I have to input single digit values in my code where it adds up all the values I input and then show the Lowest number inputed and the Highest number inputed. The code works perfectly when adding up the values no matter what I input BUT when trying to display the Lowest and Highest Value nothing seems to show up.
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
// The user inputed values are solved by the program
void Arrayinfo()
{
constint size = 30; // Array Size
char num[size]; // To hold the number of inputs
int count = 0,i; // Loop counter variable
cin >> num;
for (i=0; i < strlen(num); i++)
{
count += num[i] -'0';
}
cout << "The Total is " << count << endl;
int highest, lowest; // Highest and lowest user inputed value
int c, num;
highest = num[0]; // Highest
lowest = num[0]; // Lowest
for (num=1; num < size; c++)
{
if (num[c] > highest)
highest = num[c];
cout << "Highest number is: " << highest << endl;
}
for (num=1; num < size; c++)
{
if (num[c] < lowest)
lowest = num[c];
cout << "Lowest number is: " << lowest << endl;
}
}
// The heading where Program asks user to input their single
// digit values
void userinHeading()
{
cout << "Enter single digit numbers into the program: " << endl;
}
// Main Function
int main ()
{
userinHeading();
Arrayinfo();
return 0;
}
ah ok just never seen a variable declared in that manner XD. I always also declare my variables before I try to declare/initialize another variable through a formula like.
int a
int b
int sum = a + b;