I'm in an online "intro" to programming class, and for my assignments my prof. gives us the psuedocode and then expects us to convert it to c++ statements. He doesn't give as any tips and is very hard to get in touch with. For this assignment we are supposed to create a program that allows the user to enter 15 numbers, then displays each number and it's difference from the numeric average of the numbers entered. I have errors in lines 63 and 68, there may be more you can spot however... In line 63 i must be declared and I have no idea htf I should do that. And in 68 I am missing a primary expression before else, and a ";" before it. Here is my code so far, any pointers are greatly appreciated;
// Start
// Declarations
// num SIZE = 15
// num numbers[SIZE]
// num counter = 0
// num total = 0
// num average = 0
// num diffFromAvg = 0
// num SENTINEL = -1
//
// output "Please enter a positive number: "
// input numbers[counter]
// while ((counter < 15) AND (numbers[counter] <> SENTINEL))
// counter = counter + 1
// total = total + numbers[counter]
// output "Please enter a positive number: "
// input numbers[counter]
// endwhile
// if (counter > 0) then
// average = total/counter
// for i = 0 to counter - 1
// diffFromAvg = numbers[i] - average
// output "Number[",i,"]: ",numbers[i]," Difference from Average is ",diffFromAvg
// endfor
// else
// output "Processing incomplete. No values in the array."
// endif
// Stop
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main()
{
int SIZE=15;
int numbers[SIZE];
int counter=0;
double total=0;
double average=0;
double diffFromAvg=0;
int SENTINEL=-1;
cout<<"Please enter a positive number: "<<endl;
cin>>numbers[counter];
while((counter<15)&&(numbers[counter]!=SENTINEL))
{
counter=counter+1;
total=total+numbers[counter];
cout<<"Please enter a positive integer: "<<endl;
cin>>numbers[counter];
}
if(counter>0)
{
average=total/counter;
}
for(i==0; counter-1;)
{
diffFromAvg=numbers[i]-average;
cout<<"Number[",i,"]: "<<numbers[i]<<"Difference from Average is "<<diffFromAvg<<endl;
}
else
{
cout<<"Processing incomplete. No values in the array."<<endl;
}
system("PAUSE");
return 0;
}
Also, if you think I should change the structure, let me know. I have a hard time teaching myself things v.v